Hi folks,
I'm trying to get my hands on DSP plugin development by writing a simple delay line of significant amount of time (say around 20s). Later I'll process those samples but first things first.
For now, I added a m_chunk attribute to my dsp_impl_base child.
audio_chunk_impl m_chunk; // in member declaration
And during each on_chunk call I append to it
bool on_chunk(audio_chunk * chunk,abort_callback &)
{
// ...
// output the buffered stuff (hen m_chunk big enough
audio_chunk * out = insert_chunk(buffer_size * m_ch);
audio_sample * src = m_chunk.get_data();
out->set_data(src, buffer_size, m_ch, m_rate, m_ch_mask);
m_chunk.skip_first_samples(buffer_size);
// ...
// buffer the input
m_chunk.grow_data_size((buffered + sample_count) * m_ch);
audio_sample * src2 = chunk->get_data();
audio_sample * dst2 = m_chunk.get_data();
dst2 += buffered * m_ch;
for (t_size i = 0, j = sample_count * m_ch; i < j; i++)
{
*dst2++ = *src2++;
}
}
I don't want you to solve everything, and there are probably some bugs in my code, but would like a few hints!
- Is it a good idea to store input chunks in this big "audio_chunk_impl m_chunk member" ? Or would it better to instead copy each chunk to list of audio_chunk member? Or to save it in a pfc::array_t<audio_sample>? Or is it mandatory to use circular buffers (I'd like to avoid them in a first stage, and optimize that later)?
- Any idea why when I call m_chunk.skip_first_samples(buffer_size); it seems to completely empty m_chunk and not only the few samples (buffer_size) I asked? I thought skip_first_samples would simply move the chunk starting address (and probably de-allocate the skipped ones).
- Finally, a more general question, for the future steps: how often does on_chunk() method get called? Is it called at the playback speed and the chunk is then quickly sent to the hardware? Or could it go faster than the playback speed and then store somewhere the chunk (and the inserted one) until they are played? Hope this makes sense. I'm asking because I want to have a "lookahead" of ~20s of signal, but I will actually only process them only at the end of the file. Therefore, I don't need (nor want) to wait before the track starts for 20s. All I need is to have in advance the 20 last seconds of the track. (Assuming I only play tracks longer than 20s)
Please note that I'm no expert at all in c++.
Cheers!