is it possible to record from mic/line in?

Pixilang programming language
Post Reply
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

is it possible to record from mic/line in?

Post by majkol »

Hi,

First of all: thank you so much, nightradio, for making pixilang available. I've only just started playing around with it this weekend, and so far it seems awesome!

And now to my total beginners question:

Is there a way to record audio from mic/line in? The only mention of anything related I can find in the manual is enable_audio_input(), but I suspect that won't take me all the way..

I'd be extremely greatful for any pointers in the right direction!
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

Hello!

Of course, it is possible :) The problem is there is no mic/line recording examples in Pixilang. But i will make it for you
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

First. Simple Input (Mic/Line) Visualizer

Code: Select all

fn audio_callback(
    $stream,
    $userdata,
    $channels,
    $frames,
    $output_time_in_system_ticks,
    $in_channels,
    $latency_in_frames )
{
    if $in_channels >= 0
    {
        copy( visual_buf, $in_channels[ 0 ] )
    }
    ret( 0 ) //output is empty
}

visual_buf = new( 256, 1, INT16 )
clean( visual_buf )

set_audio_callback( audio_callback, 0, 44100, INT16, 2 )
enable_audio_input( 1 )

xsize = get_xsize( get_screen() )
ysize = get_ysize( get_screen() )
hxsize = xsize / 2
hysize = ysize / 2

while 1
{
    transp( 64 );
    clear()
    transp( 256 );

    x = 0 while( x < 256 )
    {
        line( x - 128, 0, x - 128, visual_buf[ x ] / 512, GREEN )
        x + 1
    }

    while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { halt } }

    frame()
}
Second. Input to Output (feedback)

Code: Select all

fn audio_callback(
    $stream,
    $userdata,
    $channels,
    $frames,
    $output_time_in_system_ticks,
    $in_channels,
    $latency_in_frames )
{
    if $in_channels >= 0
    {
        //Copy input channels to the output:
        $ch = 0 while $ch < 2
        {
            copy( $channels[ $ch ], $in_channels[ $ch ], 0, 0, $frames )
            $ch + 1
        }

        //Visualization:
        copy( visual_buf, $in_channels[ 0 ] )

        ret( 1 ) //output is not empty
    }
    ret( 0 )
}

visual_buf = new( 256, 1, INT16 )
clean( visual_buf )

set_audio_callback( audio_callback, 0, 44100, INT16, 2 )
enable_audio_input( 1 )

xsize = get_xsize( get_screen() )
ysize = get_ysize( get_screen() )
hxsize = xsize / 2
hysize = ysize / 2

while 1
{
    transp( 64 );
    clear()
    transp( 256 );

    x = 0 while( x < 256 )
    {
        line( x - 128, 0, x - 128, visual_buf[ x ] / 512, GREEN )
        x + 1
    }

    while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { halt } }

    frame()
}
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

Re: is it possible to record from mic/line in?

Post by majkol »

Hey! Thank you so much for the very quick reply, and even more for posting example code! It looks very easy to do something usable with audio in - I'll have a go at it tonight. This is exactly how you make people use your stuff! :good:
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

Re: is it possible to record from mic/line in?

Post by majkol »

Hi again,

I'm back, bothering you for more help... :oops:

I've managed to understand and run the example code on my nexus 5, and it works great. Now my problem is that i need to switch from recording from mic to recording from line in. On win7, that is easily done by selecting the proper input device in the prefs, but on the android version the only option seems to be "auto", which defaults to the mic. I can hear the sound i'm playing through line in, so i know the connection is ok, but the example program only reacts to the sound coming in via the mic. Is there a way of switching devices from within the code, or is it maybe a matter of selecting the proper x for $in_channels[ x ] in the audio callback? I tried x = 2 and x = 3, but that didn't seem to make any change... Please help, and big thanks in advance!
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

Hm... Nexus 5 has separate Line-in port? :) I've never seen Android devices with line-in.
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

Re: is it possible to record from mic/line in?

Post by majkol »

Oh, no, it's a single 4-pole connection. What i mean is that even though the cable is inserted, pixilang records from the built in mic. Very weird, i agree. Maybe it's a hardware thing on my part?
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

Re: is it possible to record from mic/line in?

Post by majkol »

I'll make sure that i can record sound via cable into other apps, and get back to you if the problem persists!
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

Ah, ok. Please try to insert the Line-in before Pixilang launch.
majkol
Posts: 6
Joined: Mon Feb 03, 2014 12:46 am

Re: is it possible to record from mic/line in?

Post by majkol »

Hi again,

This seems to be something that affects the phone in general, not just pixilang. Not sure if it's software or hardware, but after a couple of reboots and some disconnecting and reconnecting i finally get a signal from line in. Sorry to bother you about it when i should be bothering google (or possibly LG)! =)
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

Ok :)
Pixilang and all my Android apps use the OpenSL for audio. OpenSL uses default system Audio Input and Output. So theoretically it should switch between the different audio ports automatically :) But unfortunately it is very dependent on device. My LG E510 does not work perfectly too
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

Re: is it possible to record from mic/line in?

Post by kmatze »

NightRadio wrote:First. Simple Input (Mic/Line) Visualizer

Code: Select all

...
}
Second. Input to Output (feedback)

Code: Select all

...
}
hi nightradio,
nice sample.
the second sample has a little echo.
i use standard audio on a notebook.
i test it with driver asio4all and the echo is less then the standard, but it is. I think thats a general problem with the latenz. is there a programming trick in pixilang to reduce the latenz?

greetings - kmatze
User avatar
NightRadio
Site Admin
Posts: 3550
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: is it possible to record from mic/line in?

Post by NightRadio »

In code - no. But you can change the audio parameters in the pixilang_config.ini
Format is the same as in SunVox: http://www.warmplace.ru/wiki/sunvox:man ... figuration
Post Reply