Home --> Documentations --> PJMEDIA Reference
This example demonstrates how to use Resample Port to change the sampling rate of the media streams.
This file is pjsip-apps/src/samples/resampleplay.c
32#include <pjlib-util.h>
41#define THIS_FILE "resampleplay.c"
44static const char *desc =
51" Demonstrate how use resample port to play a WAV file to sound \n"
52" device using different sampling rate. \n"
56" resampleplay [options] FILE.WAV \n"
61" The WAV file could have mono or stereo channels with arbitrary \n"
62" sampling rate, but MUST contain uncompressed (i.e. 16bit) PCM. \n";
65int main( int argc, char *argv[])
77 int sampling_rate = CLOCK_RATE;
78 int channel_count = NCHANNELS;
79 int samples_per_frame = NSAMPLES;
80 int bits_per_sample = NBITS;
90 if (get_snd_options(THIS_FILE, argc, argv, &dev_id, &sampling_rate,
91 &channel_count, &samples_per_frame, &bits_per_sample))
98 if (!argv[pj_optind]) {
99 puts( "Error: no file is specified");
126 app_perror(THIS_FILE, "Unable to open file", status);
132 PJ_LOG(3,(THIS_FILE, "Error: file has different number of channels. "
133 "Perhaps you'd need -c option?"));
146 app_perror(THIS_FILE, "Unable to create resample port", status);
163 app_perror(THIS_FILE, "Unable to open sound device", status);
170 app_perror(THIS_FILE, "Error connecting sound ports", status);
176 dump_pool_usage(THIS_FILE, &cp);
187 printf( "Playing %s at sampling rate %d (original file sampling rate=%d)\n",
188 argv[pj_optind], sampling_rate,
191 puts( "Press <ENTER> to stop playing and quit");
193 if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
194 puts( "EOF while reading stdin, will quit now..");
pj_status_t pjmedia_endpt_create(pj_pool_factory *pf, pj_ioqueue_t *ioqueue, unsigned worker_cnt, pjmedia_endpt **p_endpt) Definition: endpoint.h:127
pj_status_t pjmedia_endpt_destroy(pjmedia_endpt *endpt) Definition: endpoint.h:168
pj_status_t pjmedia_snd_port_connect(pjmedia_snd_port *snd_port, pjmedia_port *port)
pj_status_t pjmedia_snd_port_create(pj_pool_t *pool, int rec_id, int play_id, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, unsigned options, pjmedia_snd_port **p_port)
pj_status_t pjmedia_snd_port_destroy(pjmedia_snd_port *snd_port)
struct pjmedia_snd_port pjmedia_snd_port Definition: sound_port.h:145
pj_status_t pj_init(void)
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
#define PJ_LOG(level, arg)
pj_pool_factory_policy pj_pool_factory_default_policy
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
void pj_pool_release(pj_pool_t *pool)
pj_status_t pj_thread_sleep(unsigned msec)
#define PJ_ASSERT_RETURN(expr, retval)
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|