I found this answer: http://gstreamer-devel.966125.n4.nabble.com/Convertion-of-GstBuffer-to-PCM-audio-data-td4676543.html , and this is very close to my question, however, I'm still wondering if the same applies to mp3 files. I have to calculate the Fourier transform of the songs, that's the reason for the need of getting the songs/samples as an array of numbers.
I tried the get_buffer() method, mapped it into a MapInfoData object and saved the samples, and this time I got an array with length of 383*4608 for my 10 second mp3 file, where 383 is the number of samples and 4608 is the size of buffer. A saved each element for sample data to an 8-bit unsigned int for the test, but <a href="https://superuser.com/a/1173507" target="_top" rel="nofollow" link="external">this</a> answer says that bit depth may alter for each sample in the case of mp3.
Here are the relevant parts from my code:
GstFlowReturn sample_arrived(GstAppSink *appsink, AudioStreamer *audio_streamer)
{
if (!gst_app_sink_is_eos(appsink))
{
GstSample *sample = gst_app_sink_pull_sample(appsink);
//assert(sample);
audio_streamer->_samples.push(sample);
GstBuffer *buffer = gst_sample_get_buffer(sample);
GstMapInfo info;
if (gst_buffer_map(buffer, &info, GST_MAP_READ))
{
for ( guint i = 0; i < info.size; ++i)
//g_print("%u\n", info.data[i]);
audio_streamer->_tmp_samples.push(info.data[i]); //type of _tmp_samples: std::queue<guint8>
}
gst_buffer_unmap (buffer, &info);
gst_sample_unref(sample);
}
return GST_FLOW_OK;
}
Is this the right way for doing this?
<br/><hr align="left" width="300" />
Sent from the <a href="http://gstreamer-devel.966125.n4.nabble.com/">GStreamer-devel mailing list archive</a> at Nabble.com.<br/>