I have a double pointer data->mono_channel, where I would like to cast all the doubles to integers and put them in an array.
int frames = data->audio_info_save->frames;
short buffer[frames];
double* p;
int i = 0;
for (p = &(data->mono_channel)[0]; p < &(data->mono_channel)[frames]; p++) {
buffer[i] = (int) *p;
i++;
}
The purpose is that ALSA takes an integer array of samples, and my samples are in doubles.
if ((err = snd_pcm_writei(playback_handle, buffer, frames)) != frames) {
fprintf(stderr, "write to audio interface failed (%s)\n", snd_strerror(err));
exit(1);
}
So somehow I need my doubles to be casted to integers.
I don't hear any sound. So is the casting done correctly?