Extracing data from samples

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracing data from samples

krrr
Hello,

I have a playbin with an appsink, and my goal is to gain raw data out of
audio files. For this, I have a "new-sample" signal  attached to the
appsink, and when a sample arrives, I use the gst_app_sink_pull_sample()
function to get it, then query the buffer that belongs to the sample,
finally I save sample info into a GstMapInfo object. According to the  docs
<https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstMemory.html#GstMapInfo>
, the GstMapInfo has a member called data, and I supposed that raw samples
are accessible  through this member, but the content of info.data changes
every time I run my application. Also, they are unsigned 8-bit integers, and
when I tested reading the same mp3 file with a Python module, the data
points (or samples) had quite different values, some of them were more than
255 and some of them were negative numbers. Another thing I don't understand
that if the length of the input audio is 10 seconds, it produces only 382 or
383 samples, however the sample rate seems to be the usual 44 100 Hz,
according to this there should be about 441 000 samples per 10 seconds. What
am I doing wrong? Can someone make this clear?

Thank,
R



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Extracing data from samples

krrr
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 this 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 } gst_buffer_unmap (buffer, &info); gst_sample_unref(sample); } return GST_FLOW_OK; } Is this the right way for doing this?

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
Reply | Threaded
Open this post in threaded view
|

Re: Extracing data from samples

krrr
Sorry, here is the link of the code: https://paste2.org/UpN5xtfO

krrr <[hidden email]> ezt írta (időpont: 2018. dec. 11., K, 18:57):
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 this 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 } gst_buffer_unmap (buffer, &info); gst_sample_unref(sample); } return GST_FLOW_OK; } Is this the right way for doing this?

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

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel