This project has moved and is read-only. For the latest updates, please go here.

InitRecord"Without"Playback ASIO?

Dec 16, 2013 at 5:43 PM
Currently the ASIO implementation doesn´t allow this from what i can see,
You are forced to Initialize it with a waveprovider first.

InitRecordAndPlayback(waveIn, 2, 48000);

Like this.
You have to Playback to use Record.

Isn´t there a way to only use the Record function, as i think there should be, i don´t think it´s limited to see both, but then again i am not into the ASIO specifics.
Dec 19, 2013 at 12:36 AM
set the first parameter to null to record only
Dec 19, 2013 at 5:59 AM
Ah, didn´t know that, thanks.

Another thing though, about the - e.GetAsInterleavedSamples();

Can you make an example of that one?

As i can´t get how to use it correctly, as it want´s you to write: e.GetAsInterleavedSamples(ByteArray);

The problem with that is, you don´t know the size of the byte array, so you have to do like this:

var bytearray = new byte[e.GetAsInterleavedSamples().Length);

e.GetAsInterleavedSamples();

Which is wrong, as i get an "error" saying that you can improve performance by only using: e.GetAsInterleavedSamples(bytarray); then reusing the bytearray.

I am a bit confused how to get that working.
Dec 19, 2013 at 11:59 AM
use e,BytesRecorded to size the array. With ASIO you alwatys know the buffer size in advance anyway. This is a performance optimisation. ASIO is for ultra low latency work, and should only be used if you are happy to do more low level byte manipulation yourself.
Dec 19, 2013 at 1:24 PM
Edited Dec 19, 2013 at 1:27 PM
e.BytesRecorded doesn´t exist on ASIO.

And yeah i am more than happy to play around with low level byte manipulation. Sorry for asking so many questions though, i try to figure most out myself.
    private void AsioTesting(object sender, AsioAudioAvailableEventArgs e)
    {

        float[] samplearray = e.GetAsInterleavedSamples();
        var byteArray = new byte[samplearray.Length * 4];
        Buffer.BlockCopy(samplearray, 0, byteArray, 0, byteArray.Length);
        var byteArray2 = Float16Bit(byteArray.Length, byteArray);
        if (connect)
        {
            if (AudioDevice != "Wasapi Loopback")
                SendQueue.Add(Float16Bit(byteArray.Length, byteArray));
            if (AsioRecord)
            {
                waveWriterYour.Write(byteArray2, 0, byteArray2.Length);
            }
        }
    }
Here is my code, though i think it´s unoptimized, as i know you said in another topic to use,
Wavebuffer instead of BlockCopy, but i don´t know how to do that, as it want´s "Short" samples, ASIO gives "Float".

And as you can see, i am using e.GetAsInterleavedSamples() wrong, and can´t find the length, except by using ".Length" from it, which in turns means i am using it wrong.
Dec 23, 2013 at 8:30 PM
With ASIO, the buffer size is constant. The easy way is just to make a large buffer. It can be larger than the needed size. The function returns the number of bytes written.
Jan 3, 2014 at 10:07 PM
Ah so if i set it to, let´s say 1024bytes, then write e.GetAsInterleavedSamlples(bytes), it will turn it to 233bytes (if that is the size)?
and thusly i can move around without worrying about the "empty bytes"?
Jan 9, 2014 at 1:38 PM
yes, just read out the number of samples actually returned