Hello,
I am trying to get GStreamer to play raw sample data (32-bit float stereo) which I have loaded from a file using the appsrc element.
(I know that I could use filesrc for this, but the program will evolve to play output samples from a non-gstreamer library stored in memory)
I have adapted code taken from this example, and have had success getting it to play an 8-bit mono sample.
code
However I am having problems getting it to play float samples and getting it to use more than 1 channel.
When I try to play an 8-bit stereo sample (by changing the number of samples which in the end gets passed to gst_audio_info_set_format at line 190),
the audio playback keeps stopping and starting and playing twice the speed.
159c159 < load_raw(&data, "./wicked dub_8.raw", 44100, 1); --- > load_raw(&data, "./wicked dub_8s.raw", 44100, 2);Meanwhile, when I try to play a mono 32-bit float sample, it sounds distorted for some reason. 11c11 < #define SAMPLE uint8_t --- > #define SAMPLE float 159c159 < load_raw(&data, "./wicked dub_8.raw", 44100, 1); --- > load_raw(&data, "./wicked dub_f32.raw", 44100, 1); 190c190 < gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_U8, (gint) data.samplerate, (gint) data.channels, NULL); --- > gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_F32LE, (gint) data.samplerate, (gint) data.channels, NULL);Does anyone have any idea as to what I am missing or doing wrong? Thanks in advance Albert PS: Here are the samples I've been using. Sent from the GStreamer-devel mailing list archive at Nabble.com. _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
On Mon, 2017-12-11 at 10:37 -0700, Albert Tomanek wrote:
Hi Albert, Are you sure your buffers are properly timestamped and carry the right duration? Your num_samples calculation needs to account for the number of channels as well, and your duration calculation should account for both sample size and number of channels if I'm not mistaken (and ideally it should calculate the timestamp for data->playback_offset+num_samples and subtract the current timestamp from it, to avoid rounding errors. Cheers -Tim -- Tim Müller, Centricular Ltd - http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hello Tim, thank you for your guidance!
I indeed didn't account for the number of channels or samples when calculating num_samples and the duration. I also wasn't totally clear with myself about whether I was counting samples or frames (ie. one sample for each channel), which may have also been causing me problems. The program can now successfully play mono 32-bit float samples (this is my updated code), however when I give it a stereo sample, it seems to be played at half the speed and seems to be drawn twice on the wavescope, despite me setting the number of channels to 2 in the code: I imagine that a possible cause for this could be that multiple channels are stored differently in the file than GStreamer expects. I think that the sample data is stored in the file with the channels alternating every sample -- is this how GStreamer expects the samples to be stored? The program now also sends an EOS event once the end of the sample is reached to prevent a seg-fault: if (data->playback_offset >= data->size) { gst_app_src_end_of_stream ((GstAppSrc *) data->app_source); }This works, however the program plays silence for once more the sample's length after the end is reached. Do you have any idea about what may be causing these problems? Thanks -- Albert Sent from the GStreamer-devel mailing list archive at Nabble.com. _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |