[gst-devel] audioresample

Cai Yuanqing yuanqing.cai at tieto.com
Mon Jan 17 03:26:19 CET 2011


  Hi,

On 01/13/2011 01:39 PM, Anuroop Jesu wrote:
> Hi ,
>
> I Tried the suggestion provided for the by Cai. Thanks for the code Cai.
>
> It works something like this It only allows to playback the 22KHz 
> S16LE audio.
>
> What I was trying is to convert the any input format into a 22KHz 
> S16LE so I can mux it with other stream of the same property and  mux 
> multiple streams using alsasink plug:dmix.
I see what you mean :-)
I tried pipeline like this:
gst-launch-0.10 filesrc location=yellow.mp3 ! id3demux ! mad ! 
audioconvert ! audioresample ! 
'audio/x-raw-int,width=16,depth=16,rate=22050,channels=2,endianness=1234,signed=true' 
! alsasink

It works well to first decode any type of mp3 files into PCM,and then 
re-sample them into 
'audio/x-raw-int,width=16,depth=16,rate=22050,channels=2,endianness=1234,signed=true.
So you can playback this stream ,or you can replace 'alsasink' to other 
elements:

$ file yellow.mp3
yellow.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, 
layer III, v1, 128 kbps, 44.1 kHz, JntStereo

$ gst-launch-0.10 filesrc location=yellow.mp3 ! id3demux ! mad ! 
audioconvert ! audioresample ! 
'audio/x-raw-int,width=16,depth=16,rate=22050,channels=2,endianness=1234,signed=true' 
! lame ! filesink location=haha.mp3

$ file haha.mp3
haha.mp3: MPEG ADTS, layer III, v2, 128 kbps, 22.05 kHz, JntStereo


The pipeline above turn your stream to encode int a mp3 file with 
property as 
'audio/x-raw-int,width=16,depth=16,rate=22050,channels=2,endianness=1234,signed=true'.

Just add elements behind audioresample and caps in the C code.

Hope it helps :-)

Thanks.




>
> With Warm Regards
> Jesu Anuroop Suresh
>
> "Any intelligent fool can make things bigger, more complex, and more 
> violent. It takes a touch of genius -- and a lot of courage -- to move 
> in the opposite direction."
> "Anyone who has never made a mistake has never tried anything new."
>
>
>
>
>
>
> On Thu, Jan 13, 2011 at 9:51 AM, Jesu Anuroop Suresh <jesuas at gmail.com 
> <mailto:jesuas at gmail.com>> wrote:
>
>     Hi Cai,
>
>
>     Thanks for you response, I Will try out your suggestion of using
>     the filtered link.
>
>     Sorry there was some typoerror in my code what I shared.
>
>     I did initialized the 'resmux' as capasity filter and used the
>     conv not conv1.
>
>     The cocde works for me for mp3 playback in its original settings.
>
>
>             resample = gst_element_factory_make ("audioresample",
>     "audio-resample");
>             conv     = gst_element_factory_make ("audioconvert",
>      "converter1");
>     resmux   = gst_element_factory_make ("capsfilter", "filter");
>
>             caps = gst_caps_new_simple ("audio/x-raw-int",
>                                          "width", G_TYPE_INT, 16,
>                                          "depth", G_TYPE_INT, 16,
>                                          "rate",  G_TYPE_INT, 22050,
>                                          "channels",G_TYPE_INT, 2, NULL
>                                          );
>
>             if (!musicPlayer.playPipeline || !source || !sink ||
>                 !resample || !resmux || !caps || !conv)
>             {
>                 g_print ("NO MEM Exiting.\n");
>                 return 1;
>             }
>
>             /* we set the input filename to the source element */
>             g_object_set (G_OBJECT (source), "location", filePath, NULL);
>
>             demuxer  = gst_element_factory_make ("id3demux",
>     "id3-demuxer");
>             decoder  = gst_element_factory_make ("mad", "mp3-decoder");
>
>              if (!demuxer || !decoder || !conv)
>              {
>                         g_print ("NO MEM Exiting.\n");
>                         return 1;
>               }
>
>     With Warm Regards
>     Jesu Anuroop Suresh
>
>     "Any intelligent fool can make things bigger, more complex, and
>     more violent. It takes a touch of genius -- and a lot of courage
>     -- to move in the opposite direction."
>     "Anyone who has never made a mistake has never tried anything new."
>
>     On Thu, Jan 13, 2011 at 7:16 AM, Cai Yuanqing [via
>     GStreamer-devel] <[hidden email]
>     <http://user/SendEmail.jtp?type=node&node=3215225&i=0>> wrote:
>
>           Hi Suresh:
>              Your application have a little problem. :-)
>
>
>         On 01/12/2011 08:41 PM, Jesu Anuroop Suresh wrote:
>
>         > Hi Sean,
>         >
>         > Yes, what I was trying is to resample the decoded mp3 data
>         to the
>         > fixed (22KHZ S16LE) formate,
>         >
>         > no matter what is the input rate using a C application.
>         >
>         > Thanks for your response.
>         >
>         > Here is the piece of the code for the same but it does not
>         work  with
>         > audioresample with the caps filter 'resmux'. This code does
>         work
>         > without the caps filter 'resmux'.
>         >
>         >         GstElement *source, *demuxer, *decoder, *conv, *sink,
>         > *resample, *resmux;
>         >         GstCaps *caps;
>         >
>         >         gst_init(NULL, NULL);
>         >
>         >         /* Create gstreamer elements */
>         >         musicPlayer.playPipeline = gst_pipeline_new
>         ("audio-player");
>         >         source   = gst_element_factory_make ("filesrc",
>         "file-source");
>         >         sink     = gst_element_factory_make ("alsasink",
>         "audio-output");
>         >         resample = gst_element_factory_make ("audioresample",
>         > "audio-resample");
>         >         conv     = gst_element_factory_make ("audioconvert",
>         >  "converter1");
>         >
>         >         caps = gst_caps_new_simple ("audio/x-raw-int",
>         >                                      "width", G_TYPE_INT, 16,
>         >                                      "depth", G_TYPE_INT, 16,
>         >                                      "rate",  G_TYPE_INT,
>         22050,
>         >                                      "channels",G_TYPE_INT,
>         2, NULL
>         >                                      );
>         >
>         >         if (!musicPlayer.playPipeline || !source || !sink ||
>         >             !resample || !resmux || !caps || !conv)
>         >         {
>         >             g_print ("NO MEM Exiting.\n");
>         >             return 1;
>         >         }
>         resmux is not initialized yet,here maybe some random
>         value,you'd better
>         remove it from check list.
>
>         >
>         >         /* we set the input filename to the source element */
>         >         g_object_set (G_OBJECT (source), "location",
>         filePath, NULL);
>         >
>         >         demuxer  = gst_element_factory_make ("id3demux",
>         "id3-demuxer");
>         >         decoder  = gst_element_factory_make ("mad",
>         "mp3-decoder");
>         >
>         >          if (!demuxer || !decoder || !conv1)
>         conv1 ? dose it should be conv?
>
>         >          {
>         >                     g_print ("NO MEM Exiting.\n");
>         >                     return 1;
>         >           }
>         >
>         >          g_object_set (G_OBJECT (resmux), "caps", caps, NULL);
>         >          gst_caps_unref (caps);
>         >
>         as I said before,resmux haven't initialized ,that's not quite
>         right.
>         and I suggest you to remove these two lines.
>
>         >          /* file-source -> demuxer -> decoder ->
>          alsa-output */
>         >         gst_bin_add_many (GST_BIN (musicPlayer.playPipeline),
>         >                          source, demuxer, decoder, conv,
>         resample,
>         > resmux,sink, NULL);
>         >
>         >         gst_element_link (source, demuxer);
>         >         gst_element_link_many (decoder, conv,
>         resample,resmux,sink, NULL);
>         You can use gst_element_link_filtered to link resample and
>         sink with
>         caps instead of this way.
>         something like:
>              gst_element_link (source, demuxer);
>              gst_element_link_many (decoder, conv, resample, NULL);
>              if ( !gst_element_link_filtered(resample,sink,caps) ){
>                  g_printerr("Failed to link elements resample and
>         alsa-sink");
>              }
>
>
>         >         g_signal_connect (demuxer, "pad-added", G_CALLBACK
>         > (on_pad_added), decoder);
>         >
>         >         GstBus *bus =
>         > gst_pipeline_get_bus(GST_PIPELINE(musicPlayer.playPipeline));
>         >         gst_bus_add_watch(bus, bus_call, NULL);
>         >         gst_object_unref(bus);
>         >
>         >        
>         gst_element_set_state(GST_ELEMENT(musicPlayer.playPipeline),
>         > GST_STATE_PLAYING);
>         >
>         >         musicPlayer.playLoop = g_main_loop_new(NULL, FALSE);
>         >
>         >         g_main_loop_run(musicPlayer.playLoop);
>         >
>         >        
>         gst_element_set_state(GST_ELEMENT(musicPlayer.playPipeline),
>         > GST_STATE_NULL);
>         >         gst_object_unref(GST_OBJECT(musicPlayer.playPipeline));
>         >
>         >
>         >
>         >
>         > With Warm Regards
>         > Jesu Anuroop Suresh
>         >
>         > "Any intelligent fool can make things bigger, more complex,
>         and more
>         > violent. It takes a touch of genius -- and a lot of courage
>         -- to move
>         > in the opposite direction."
>         > "Anyone who has never made a mistake has never tried
>         anything new."
>         >
>         >
>         I attached my modified source code ,you can try it.
>         Hope it helps.
>
>         Thanks.
>
>
>         -- 
>         B.R
>
>         Cai Yuanqing
>
>
>         ------------------------------------------------------------------------------
>
>         Protect Your Site and Customers from Malware Attacks
>         Learn about various malware tactics and how to avoid them.
>         Understand
>         malware threats, the impact they can have on your business,
>         and how you
>         can protect your company and customers by using code signing.
>         http://p.sf.net/sfu/oracle-sfdevnl
>         _______________________________________________
>         gstreamer-devel mailing list
>         [hidden email]
>         <http://user/SendEmail.jtp?type=node&node=3215098&i=0>
>         https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>
>
>         ------------------------------------------------------------------------
>         View message @
>         http://gstreamer-devel.966125.n4.nabble.com/audioresample-tp3213586p3215098.html
>         <http://gstreamer-devel.966125.n4.nabble.com/audioresample-tp3213586p3215098.html?by-user=t>
>
>
>         To unsubscribe from audioresample, click here
>         <http://gstreamer-devel.966125.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3213586&code=amVzdWFzQGdtYWlsLmNvbXwzMjEzNTg2fDcwOTc3MzYyOA==&by-user=t>.
>
>
>
>
>     ------------------------------------------------------------------------
>     View this message in context: Re: audioresample
>     <http://gstreamer-devel.966125.n4.nabble.com/audioresample-tp3213586p3215225.html>
>
>
>     Sent from the GStreamer-devel mailing list archive
>     <http://gstreamer-devel.966125.n4.nabble.com/> at Nabble.com.
>
>     ------------------------------------------------------------------------------
>     Protect Your Site and Customers from Malware Attacks
>     Learn about various malware tactics and how to avoid them. Understand
>     malware threats, the impact they can have on your business, and
>     how you
>     can protect your company and customers by using code signing.
>     http://p.sf.net/sfu/oracle-sfdevnl
>     _______________________________________________
>     gstreamer-devel mailing list
>     gstreamer-devel at lists.sourceforge.net
>     <mailto:gstreamer-devel at lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>
>


-- 
B.R

Cai Yuanqing





More information about the gstreamer-devel mailing list