Changeset 3578:4480c38a3150 in roaraudio for roard
- Timestamp:
- 02/27/10 21:34:09 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/beep.c
r3577 r3578 26 26 #include "roard.h" 27 27 28 // TODO: FIXME: move them out of here into libroar: 29 static ssize_t beep_read (struct roar_vio_calls * vio, void *buf, size_t count) { 30 ROAR_DBG("beep_read(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count); 31 32 if ( vio->inst == NULL ) 33 return 0; 34 35 if ( roar_buffer_shift_out(&(vio->inst), buf, &count) == -1 ) 36 return -1; 37 38 return count; 39 } 40 41 static int beep_close (struct roar_vio_calls * vio) { 42 ROAR_DBG("beep_close(vio=%p) = ?", vio); 43 44 if ( vio->inst != NULL ) 45 roar_buffer_free(vio->inst); 46 47 ROAR_DBG("beep_close(vio=%p) = 0", vio); 48 return 0; 49 } 50 51 static void beep_init_vio (struct roar_vio_calls * vio, void * inst) { 52 ROAR_DBG("beep_init_vio(vio=%p, inst=%p) = ?", vio, inst); 53 54 memset(vio, 0, sizeof(struct roar_vio_calls)); 55 56 vio->inst = inst; 57 vio->read = beep_read; 58 vio->close = beep_close; 59 60 ROAR_DBG("beep_init_vio(vio=%p, inst=%p) = (void)", vio, inst); 61 } 62 63 struct roar_buffer * beep_fill_buffer (struct roar_beep * beep, struct roar_audio_info * info) { 64 struct roar_buffer * buf; 65 size_t frames = beep->time * info->rate / 1000; 66 size_t samples = frames * info->channels; 67 size_t mod = info->rate / beep->freq; 68 char * data; 69 char val; 70 size_t pos; 71 size_t chan; 72 73 ROAR_DBG("beep_fill_buffer(beep=%p, info=%p) = ?", beep, info); 74 75 if ( roar_buffer_new(&buf, samples) == -1 ) 76 return NULL; 77 78 if ( roar_buffer_get_data(buf, &data) == -1 ) { 79 roar_buffer_free(buf); 80 ROAR_DBG("beep_fill_buffer(beep=%p, info=%p) = NULL", beep, info); 81 return NULL; 82 } 83 84 for (pos = 0; pos < frames; pos++) { 85 val = (pos % mod) < mod/2 ? -128 : 127; 86 for (chan = 0; chan < info->channels; chan++) 87 data[pos*info->channels + chan] = val; 88 } 89 90 ROAR_DBG("beep_fill_buffer(beep=%p, info=%p) = %p", beep, info, buf); 91 return buf; 92 } 93 28 94 int beep_start (int client, struct roar_beep * beep) { 29 struct roar_stream_server * ss; 30 struct roar_stream * s; 95 struct roar_stream_server * ss; 96 struct roar_stream * s; 97 struct roar_buffer * buf; 31 98 int stream; 99 100 ROAR_DBG("beep_start(client=%i, beep=%p) = ?", client, beep); 32 101 33 102 if ( beep->vol == 0 ) … … 55 124 return -1; 56 125 126 ROAR_DBG("beep_start(client=%i, beep=%p) = ?", client, beep); 127 57 128 if ((stream = streams_new()) == -1 ) 58 129 return -1; 130 131 ROAR_DBG("beep_start(client=%i, beep=%p): stream=%i", client, beep, stream); 59 132 60 133 if ( client_stream_add(client, stream) == -1 ) { … … 78 151 79 152 s->info.channels = 1; 153 s->info.bits = 8; 80 154 81 155 if ( streams_set_dir(stream, ROAR_DIR_PLAY, 1) == -1 ) { … … 84 158 } 85 159 160 if ( (buf = beep_fill_buffer(beep, &(s->info))) == NULL ) { 161 streams_delete(stream); 162 return -1; 163 } 164 165 ROAR_DBG("beep_start(client=%i, beep=%p): buf=%p", client, beep, buf); 166 167 beep_init_vio(&(ss->vio), buf); 168 169 if ( streams_set_fh(stream, -2) == -1 ) { 170 streams_delete(stream); 171 return -1; 172 } 173 174 ROAR_DBG("beep_start(client=%i, beep=%p) = %i", client, beep, stream); 86 175 return stream; 87 176 }
Note: See TracChangeset
for help on using the changeset viewer.