[992] | 1 | //codecfilter_wave.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "roard.h" |
---|
| 26 | |
---|
| 27 | #ifdef ROAR_HAVE_LIBFISHSOUND |
---|
| 28 | |
---|
| 29 | int cf_fishsound_decoded_float (FishSound * fsound, float ** pcm, long frames, void * user_data) { |
---|
| 30 | return -1; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | int cf_fishsound_read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) { |
---|
| 34 | FishSound * fsound = (FishSound *)user_data; |
---|
| 35 | |
---|
| 36 | fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s); |
---|
| 37 | fish_sound_decode (fsound, op->packet, op->bytes); |
---|
| 38 | |
---|
| 39 | return 0; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int cf_fishsound_open(CODECFILTER_USERDATA_T * inst, int codec, |
---|
| 43 | struct roar_stream_server * info, |
---|
| 44 | struct roar_codecfilter * filter) { |
---|
| 45 | struct codecfilter_fishsound_inst * self = malloc(sizeof(struct codecfilter_fishsound_inst)); |
---|
| 46 | struct roar_stream * s = ROAR_STREAM(info); |
---|
| 47 | |
---|
| 48 | if ( !self ) |
---|
| 49 | return -1; |
---|
| 50 | |
---|
| 51 | if ( s->dir != ROAR_DIR_PLAY ) { |
---|
| 52 | free(self); |
---|
| 53 | return -1; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | self->stream = info; |
---|
| 57 | self->opened = 0; |
---|
| 58 | self->fsound = fish_sound_new(FISH_SOUND_DECODE, &(self->fsinfo)); |
---|
| 59 | |
---|
| 60 | fish_sound_set_interleave(self->fsound, 1); |
---|
| 61 | fish_sound_set_decoded_float_ilv(self->fsound, cf_fishsound_decoded_float, (void*)self); |
---|
| 62 | |
---|
| 63 | self->oggz = oggz_new(OGGZ_READ); |
---|
| 64 | |
---|
| 65 | oggz_set_read_callback(self->oggz, -1, cf_fishsound_read_packet, self->fsound); |
---|
| 66 | |
---|
| 67 | *inst = (CODECFILTER_USERDATA_T) self; |
---|
| 68 | |
---|
| 69 | return 0; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | int cf_fishsound_close(CODECFILTER_USERDATA_T inst) { |
---|
| 73 | struct codecfilter_fishsound_inst * self = (struct codecfilter_fishsound_inst *) inst; |
---|
| 74 | |
---|
| 75 | if ( inst == NULL ) |
---|
| 76 | return -1; |
---|
| 77 | |
---|
| 78 | oggz_close(self->oggz); |
---|
| 79 | fish_sound_delete(self->fsound); |
---|
| 80 | |
---|
| 81 | free(inst); |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | int cf_fishsound_read(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
| 86 | struct codecfilter_fishsound_inst * self = (struct codecfilter_fishsound_inst *) inst; |
---|
| 87 | struct roar_stream * s = ROAR_STREAM(self->stream); |
---|
| 88 | long inlen; |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | if ( self->opened ) { |
---|
| 92 | // return stream_vio_s_read(self->stream, buf, len); |
---|
| 93 | } else { |
---|
| 94 | /-* |
---|
| 95 | if (stream_vio_s_read(self->stream, tbuf, 44) != 44) { |
---|
| 96 | return -1; |
---|
| 97 | } |
---|
| 98 | *ä/ |
---|
| 99 | |
---|
| 100 | self->opened = 1; |
---|
| 101 | |
---|
| 102 | errno = EAGAIN; |
---|
| 103 | return -1; |
---|
| 104 | } |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | if ( (inlen = stream_vio_s_read(self->stream, buf, len)) == -1 ) |
---|
| 108 | return -1; |
---|
| 109 | |
---|
| 110 | oggz_read_input(self->oggz, (unsigned char *)buf, inlen); |
---|
| 111 | |
---|
| 112 | if ( !self->opened ) { |
---|
| 113 | s->info.channels = self->fsinfo.channels; |
---|
| 114 | s->info.rate = self->fsinfo.samplerate; |
---|
| 115 | s->info.bits = g_sa->bits; |
---|
| 116 | s->info.codec = ROAR_CODEC_NATIVE; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return -1; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | //ll |
---|