Simple Ambisonic Decoding

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple Ambisonic Decoding

bobby donnegan
Hi there -

I have four channels of an ambisonic recording that I would like to
spatialize into a stereo image.

I've been looking at the ATK library, but I'm not exactly sure what
object I'm looking for - I'm new to this procedure.  Can anyone
suggest a straightforward way to get these files loaded into SC and
stereo-ized?

Thanks,
Bobby

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: Simple Ambisonic Decoding

DanPeterston
There are some examples in the ATK help files. If you go in the help system to Libraries>Amisonic Toolkit>Introducing the Ambisonic Toolkit you will find examples.

Specifically you will want to choose a decoder, either FoaDecoderMatrix of FoaDecoderKernel and then use the UGen FoaDecode.ar to do the decoding.

There are NRT examples located at Libraries>Amisonic Toolkit>SynthDef and NRT Examples for ATK (a decoding copied below).

(
var score, bufnum, sndPath, duration, decoder, sampleRate, headerFormat, sampleFormat, numChannels;
var offset = 0.1;

// deinfe our score
score = Score.new;

// get a buffer number from the server
bufnum = Server.default.bufferAllocator.alloc(1);

// the path to our B-Format sound file
sndPath = Atk.userSoundsDir ++ "/b-format/Pampin-On_Space.wav";

// get some info about the soundfile we are decoding for the Score requirements
SoundFile.use(
    sndPath,
    {arg soundFile;
        headerFormat = soundFile.headerFormat;
        sampleFormat = soundFile.sampleFormat;
        sampleRate = soundFile.sampleRate;
        numChannels = soundFile.numChannels;
        duration = soundFile.duration;
    }
);

// define a decoder of your choosing
// the decoder takes a score argument so that it will add the kernels to the score for you
decoder = FoaDecoderKernel.newUHJ(
    sampleRate: sampleRate,
    score: score
);

// define an encoding and decoding synth
SynthDef(\kernelDecode, {arg buffer;
    var out, src;

    // play B-format sound file from a buffer
    src = PlayBuf.ar(numChannels, buffer, BufRateScale.kr(buffer));

    // decode our B-format signal
    out = FoaDecode.ar(src, decoder);

    Out.ar(0, out);
}).load;

score.add(
    [ 0.0,
        [ 'b_allocRead', bufnum, sndPath, 0, 0 ],
        [ 's_new', 'kernelDecode', 1001, 0, 1, 'buffer', bufnum ]
    ],
);

// add commands to free the synth and buffer
score.add([ duration, [ 'n_free', 1001 ] ],);
score.add([ duration + 0.1, [ 'b_free', bufnum ] ],);

// free the kernel buffers
    bufs.do({arg buf;
        offset = offset + 0.1;
        score.add([ duration  + offset, [ 'b_free', buf.bufnum ]])
    });
});

// add the needed dummy command to stop NRT
score.add([offset + duration + 0.2, [0]] );

// render our score to a sound file
score.recordNRT(
    "/tmp/trashme",
    "~/Desktop/myDecode.wav".standardizePath,
    sampleRate: sampleRate,
    headerFormat: headerFormat,
    sampleFormat: sampleFormat,
    options: ServerOptions.new.numOutputBusChannels_(decoder.numChannels)
);

)

Hope this helps,
Dan

On Mon, Feb 12, 2018 at 12:00 PM, <[hidden email]> wrote:
Hi there -

I have four channels of an ambisonic recording that I would like to
spatialize into a stereo image.

I've been looking at the ATK library, but I'm not exactly sure what
object I'm looking for - I'm new to this procedure.  Can anyone
suggest a straightforward way to get these files loaded into SC and
stereo-ized?

Thanks,
Bobby

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|

Re: Simple Ambisonic Decoding

bobby donnegan
Thanks, Dan - this definitely helps - the only issue is that I already
have the B-format file broken up into 4 different files. Is there a
way to unify them in this process?

On Mon, Feb 12, 2018 at 3:14 PM,  <[hidden email]> wrote:

> There are some examples in the ATK help files. If you go in the help system
> to Libraries>Amisonic Toolkit>Introducing the Ambisonic Toolkit you will
> find examples.
>
> Specifically you will want to choose a decoder, either FoaDecoderMatrix of
> FoaDecoderKernel and then use the UGen FoaDecode.ar to do the decoding.
>
> There are NRT examples located at Libraries>Amisonic Toolkit>SynthDef and
> NRT Examples for ATK (a decoding copied below).
>
> (
> var score, bufnum, sndPath, duration, decoder, sampleRate, headerFormat,
> sampleFormat, numChannels;
> var offset = 0.1;
>
> // deinfe our score
> score = Score.new;
>
> // get a buffer number from the server
> bufnum = Server.default.bufferAllocator.alloc(1);
>
> // the path to our B-Format sound file
> sndPath = Atk.userSoundsDir ++ "/b-format/Pampin-On_Space.wav";
>
> // get some info about the soundfile we are decoding for the Score
> requirements
> SoundFile.use(
>     sndPath,
>     {arg soundFile;
>         headerFormat = soundFile.headerFormat;
>         sampleFormat = soundFile.sampleFormat;
>         sampleRate = soundFile.sampleRate;
>         numChannels = soundFile.numChannels;
>         duration = soundFile.duration;
>     }
> );
>
> // define a decoder of your choosing
> // the decoder takes a score argument so that it will add the kernels to the
> score for you
> decoder = FoaDecoderKernel.newUHJ(
>     sampleRate: sampleRate,
>     score: score
> );
>
> // define an encoding and decoding synth
> SynthDef(\kernelDecode, {arg buffer;
>     var out, src;
>
>     // play B-format sound file from a buffer
>     src = PlayBuf.ar(numChannels, buffer, BufRateScale.kr(buffer));
>
>     // decode our B-format signal
>     out = FoaDecode.ar(src, decoder);
>
>     Out.ar(0, out);
> }).load;
>
> score.add(
>     [ 0.0,
>         [ 'b_allocRead', bufnum, sndPath, 0, 0 ],
>         [ 's_new', 'kernelDecode', 1001, 0, 1, 'buffer', bufnum ]
>     ],
> );
>
> // add commands to free the synth and buffer
> score.add([ duration, [ 'n_free', 1001 ] ],);
> score.add([ duration + 0.1, [ 'b_free', bufnum ] ],);
>
> // free the kernel buffers
> decoder.kernel.do({arg bufs;
>     bufs.do({arg buf;
>         offset = offset + 0.1;
>         score.add([ duration  + offset, [ 'b_free', buf.bufnum ]])
>     });
> });
>
> // add the needed dummy command to stop NRT
> score.add([offset + duration + 0.2, [0]] );
>
> // render our score to a sound file
> score.recordNRT(
>     "/tmp/trashme",
>     "~/Desktop/myDecode.wav".standardizePath,
>     sampleRate: sampleRate,
>     headerFormat: headerFormat,
>     sampleFormat: sampleFormat,
>     options: ServerOptions.new.numOutputBusChannels_(decoder.numChannels)
> );
>
> )
>
> Hope this helps,
> Dan
>
> On Mon, Feb 12, 2018 at 12:00 PM, <[hidden email]> wrote:
>>
>> Hi there -
>>
>> I have four channels of an ambisonic recording that I would like to
>> spatialize into a stereo image.
>>
>> I've been looking at the ATK library, but I'm not exactly sure what
>> object I'm looking for - I'm new to this procedure.  Can anyone
>> suggest a straightforward way to get these files loaded into SC and
>> stereo-ized?
>>
>> Thanks,
>> Bobby
>>
>> _______________________________________________
>> sc-users mailing list
>>
>> info (subscription, etc.):
>> http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
>> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
>> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>
>



--
--Bobby D.--

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: Simple Ambisonic Decoding

DanPeterston
You can combine them into a 4channel file in an editor or you can do something like this...

(
var score, bufnum, sndPath, duration, decoder, sampleRate, headerFormat, sampleFormat, numChannels;
var offset = 0.1;

// deinfe our score
score = Score.new;

// get a buffer number from the server
bufnum = Server.default.bufferAllocator.alloc(4);

// the path to our B-Format sound file
sndPath = [
"~/Desktop/sound_w.wav".standardizePath,
"~/Desktop/sound_x.wav".standardizePath,
"~/Desktop/sound_y.wav".standardizePath,
"~/Desktop/sound_z.wav".standardizePath
];

// get some info about the soundfile we are decoding for the Score requirements
SoundFile.use(
    sndPath[0],
    {arg soundFile;
        headerFormat = soundFile.headerFormat;
        sampleFormat = soundFile.sampleFormat;
        sampleRate = soundFile.sampleRate;
        numChannels = soundFile.numChannels;
        duration = soundFile.duration;
    }
);

// define a decoder of your choosing
// the decoder takes a score argument so that it will add the kernels to the score for you
decoder = FoaDecoderKernel.newUHJ(
    sampleRate: sampleRate,
    score: score
);

// define an encoding and decoding synth
SynthDef(\kernelDecode, {arg buffer, buffer1, buffer2, buffer3;
    var out, src;

    // play B-format sound file from a buffer
    src = PlayBuf.ar(numChannels, [buffer, buffer1, buffer2, buffer3], BufRateScale.kr([buffer, buffer1, buffer2, buffer3]));

    // decode our B-format signal
    out = FoaDecode.ar(src, decoder);

    Out.ar(0, out);
}).load;

score.add(
    [ 0.0,
        [ 'b_allocRead', bufnum, sndPath[0], 0, 0 ],
[ 'b_allocRead', bufnum+1, sndPath[1], 0, 0 ],
[ 'b_allocRead', bufnum+2, sndPath[2], 0, 0 ],
[ 'b_allocRead', bufnum+3, sndPath[3], 0, 0 ],
[ 's_new', 'kernelDecode', 1001, 0, 1, 'buffer', bufnum, 'buffer1', bufnum+1, 'buffer2', bufnum+2, 'buffer3', bufnum+3 ]
    ],
);

// add commands to free the synth and buffer
score.add([ duration, [ 'n_free', 1001 ] ],);
score.add([ duration + 0.1, [ 'b_free', bufnum ] ],);
score.add([ duration + 0.1, [ 'b_free', bufnum+1 ] ],);
score.add([ duration + 0.1, [ 'b_free', bufnum+2 ] ],);
score.add([ duration + 0.1, [ 'b_free', bufnum+3 ] ],);

// free the kernel buffers
    bufs.do({arg buf;
        offset = offset + 0.1;
        score.add([ duration  + offset, [ 'b_free', buf.bufnum ]])
    });
});

// add the needed dummy command to stop NRT
score.add([offset + duration + 0.2, [0]] );

// render our score to a sound file
score.recordNRT(
    "/tmp/trashme",
    "~/Desktop/myDecode.wav".standardizePath,
    sampleRate: sampleRate,
    headerFormat: headerFormat,
    sampleFormat: sampleFormat,
    options: ServerOptions.new.numOutputBusChannels_(decoder.numChannels)
);

)

On Mon, Feb 12, 2018 at 2:28 PM, <[hidden email]> wrote:
Thanks, Dan - this definitely helps - the only issue is that I already
have the B-format file broken up into 4 different files. Is there a
way to unify them in this process?

On Mon, Feb 12, 2018 at 3:14 PM,  <[hidden email]> wrote:
> There are some examples in the ATK help files. If you go in the help system
> to Libraries>Amisonic Toolkit>Introducing the Ambisonic Toolkit you will
> find examples.
>
> Specifically you will want to choose a decoder, either FoaDecoderMatrix of
> FoaDecoderKernel and then use the UGen FoaDecode.ar to do the decoding.
>
> There are NRT examples located at Libraries>Amisonic Toolkit>SynthDef and
> NRT Examples for ATK (a decoding copied below).
>
> (
> var score, bufnum, sndPath, duration, decoder, sampleRate, headerFormat,
> sampleFormat, numChannels;
> var offset = 0.1;
>
> // deinfe our score
> score = Score.new;
>
> // get a buffer number from the server
> bufnum = Server.default.bufferAllocator.alloc(1);
>
> // the path to our B-Format sound file
> sndPath = Atk.userSoundsDir ++ "/b-format/Pampin-On_Space.wav";
>
> // get some info about the soundfile we are decoding for the Score
> requirements
> SoundFile.use(
>     sndPath,
>     {arg soundFile;
>         headerFormat = soundFile.headerFormat;
>         sampleFormat = soundFile.sampleFormat;
>         sampleRate = soundFile.sampleRate;
>         numChannels = soundFile.numChannels;
>         duration = soundFile.duration;
>     }
> );
>
> // define a decoder of your choosing
> // the decoder takes a score argument so that it will add the kernels to the
> score for you
> decoder = FoaDecoderKernel.newUHJ(
>     sampleRate: sampleRate,
>     score: score
> );
>
> // define an encoding and decoding synth
> SynthDef(\kernelDecode, {arg buffer;
>     var out, src;
>
>     // play B-format sound file from a buffer
>     src = PlayBuf.ar(numChannels, buffer, BufRateScale.kr(buffer));
>
>     // decode our B-format signal
>     out = FoaDecode.ar(src, decoder);
>
>     Out.ar(0, out);
> }).load;
>
> score.add(
>     [ 0.0,
>         [ 'b_allocRead', bufnum, sndPath, 0, 0 ],
>         [ 's_new', 'kernelDecode', 1001, 0, 1, 'buffer', bufnum ]
>     ],
> );
>
> // add commands to free the synth and buffer
> score.add([ duration, [ 'n_free', 1001 ] ],);
> score.add([ duration + 0.1, [ 'b_free', bufnum ] ],);
>
> // free the kernel buffers
> decoder.kernel.do({arg bufs;
>     bufs.do({arg buf;
>         offset = offset + 0.1;
>         score.add([ duration  + offset, [ 'b_free', buf.bufnum ]])
>     });
> });
>
> // add the needed dummy command to stop NRT
> score.add([offset + duration + 0.2, [0]] );
>
> // render our score to a sound file
> score.recordNRT(
>     "/tmp/trashme",
>     "~/Desktop/myDecode.wav".standardizePath,
>     sampleRate: sampleRate,
>     headerFormat: headerFormat,
>     sampleFormat: sampleFormat,
>     options: ServerOptions.new.numOutputBusChannels_(decoder.numChannels)
> );
>
> )
>
> Hope this helps,
> Dan
>
> On Mon, Feb 12, 2018 at 12:00 PM, <[hidden email]> wrote:
>>
>> Hi there -
>>
>> I have four channels of an ambisonic recording that I would like to
>> spatialize into a stereo image.
>>
>> I've been looking at the ATK library, but I'm not exactly sure what
>> object I'm looking for - I'm new to this procedure.  Can anyone
>> suggest a straightforward way to get these files loaded into SC and
>> stereo-ized?
>>
>> Thanks,
>> Bobby
>>
>> _______________________________________________
>> sc-users mailing list
>>
>> info (subscription, etc.):
>> http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
>> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
>> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>
>



--
--Bobby D.--