Home --> Documentations --> PJMEDIA Reference
This example demonstrate how to create a custom media port (in this case, a sine wave generator) and connect it to the sound device.
This file is pjsip-apps/src/samples/playsine.c
54#define THIS_FILE "playsine.c"
58static int app_perror( const char *sender, const char *title,
67 printf( "%s: %s [code=%d]\n", title, errmsg, status);
85 unsigned i, left, right;
94 for (i=0; i<count; ++i) {
95 *samples++ = sine->samples[left];
99 *samples++ = sine->samples[right];
115#define M_PI (3.14159265)
122 unsigned sampling_rate,
123 unsigned channel_count,
139 name = pj_str( "sine generator");
141 PJMEDIA_SIG_CLASS_PORT_AUD( 's', 'i'),
144 16, sampling_rate * 20 / 1000 * channel_count);
158 for( i=0; i<count; i++ )
161 sin((( double)i/( double)count) * M_PI * 8.) );
171static void usage( void)
174 puts( "Usage: playsine [nchannel]");
177 puts( " nchannel is number of audio channels (1 for mono, or 2 for stereo).");
178 puts( " Default is 1 (mono).");
186int main( int argc, char *argv[])
194 int channel_count = 1;
198 channel_count = atoi(argv[1]);
199 if (channel_count < 1 || channel_count > 2) {
200 puts( "Error: invalid arguments");
229 status = create_sine_port( pool,
235 app_perror(THIS_FILE, "Unable to create sine port", status);
251 app_perror(THIS_FILE, "Unable to open sound device", status);
272 puts( "Playing sine wave..");
274 puts( "Press <ENTER> to stop playing and quit");
276 if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
277 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_disconnect(pjmedia_snd_port *snd_port)
pj_status_t pjmedia_snd_port_create_player(pj_pool_t *pool, int index, 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)
pj_pool_factory_policy pj_pool_factory_default_policy
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
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_zalloc(pj_pool_t *pool, pj_size_t size)
void pj_pool_release(pj_pool_t *pool)
pj_str_t pj_str(char *str)
pj_status_t pj_thread_sleep(unsigned msec)
#define PJ_ASSERT_RETURN(expr, retval)
#define PJ_UNUSED_ARG(arg)
pj_str_t pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize)
Definition: confbench.c:135
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|