[2295] | 1 | //transcode_speex.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 5 | * |
---|
| 6 | * This file is part of libroardsp 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 | * libroardsp 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 "libroardsp.h" |
---|
| 26 | |
---|
| 27 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
| 28 | |
---|
| 29 | #define _16BIT (16/8) |
---|
| 30 | #define _SIZE_LEN 2 |
---|
| 31 | |
---|
[2296] | 32 | int roar_xcoder_speex_init (struct roar_xcoder * state) { |
---|
[2298] | 33 | struct roar_xcoder_speex * self = malloc(sizeof(struct roar_xcoder_speex)); |
---|
| 34 | struct roar_audio_info * info = &(state->info.pcm); |
---|
| 35 | int tmp; |
---|
| 36 | |
---|
| 37 | if ( self == NULL ) |
---|
| 38 | return -1; |
---|
| 39 | |
---|
| 40 | // curruntly only 16 bit mode is supported |
---|
| 41 | if ( info->bits != 16 ) { |
---|
| 42 | free(self); |
---|
| 43 | return -1; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | // curruntly only mono mode is supported |
---|
| 47 | if ( info->channels != 1 ) { |
---|
| 48 | free(self); |
---|
| 49 | return -1; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | memset(self, 0, sizeof(struct roar_xcoder_speex)); |
---|
| 53 | |
---|
| 54 | state->inst = self; |
---|
| 55 | |
---|
| 56 | self->mode = ROAR_SPEEX_MODE_UWB; |
---|
| 57 | |
---|
| 58 | if (state->encode) { |
---|
| 59 | switch (self->mode) { |
---|
| 60 | case ROAR_SPEEX_MODE_NB: self->xcoder = speex_encoder_init(&speex_nb_mode); break; |
---|
| 61 | case ROAR_SPEEX_MODE_WB: self->xcoder = speex_encoder_init(&speex_wb_mode); break; |
---|
| 62 | case ROAR_SPEEX_MODE_UWB: self->xcoder = speex_encoder_init(&speex_uwb_mode); break; |
---|
| 63 | } |
---|
| 64 | tmp = 8; |
---|
| 65 | speex_encoder_ctl(self->xcoder, SPEEX_SET_QUALITY, &tmp); |
---|
| 66 | speex_encoder_ctl(self->xcoder, SPEEX_GET_FRAME_SIZE, &(self->frame_size)); |
---|
| 67 | } else { |
---|
| 68 | self->xcoder = NULL; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | speex_bits_init(&(self->bits)); |
---|
| 72 | |
---|
| 73 | return 0; |
---|
[2296] | 74 | } |
---|
| 75 | |
---|
| 76 | int roar_xcoder_speex_uninit (struct roar_xcoder * state) { |
---|
[2298] | 77 | struct roar_xcoder_speex * self = state->inst; |
---|
| 78 | |
---|
| 79 | if ( self->xcoder != NULL ) { |
---|
| 80 | if (state->encode) { |
---|
| 81 | speex_encoder_destroy(self->xcoder); |
---|
| 82 | } else { |
---|
| 83 | speex_decoder_destroy(self->xcoder); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | speex_bits_destroy(&(self->bits)); |
---|
| 88 | |
---|
| 89 | free(self); |
---|
| 90 | |
---|
| 91 | return 0; |
---|
[2296] | 92 | } |
---|
| 93 | |
---|
| 94 | int roar_xcoder_speex_packet_size(struct roar_xcoder * state, int samples) { |
---|
[2298] | 95 | struct roar_xcoder_speex * self = state->inst; |
---|
| 96 | if (!state->encode) { |
---|
| 97 | return -1; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | return _16BIT * self->frame_size; |
---|
[2296] | 101 | } |
---|
| 102 | |
---|
| 103 | int roar_xcoder_speex_encode (struct roar_xcoder * state, void * buf, size_t len) { |
---|
| 104 | return -1; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | int roar_xcoder_speex_decode (struct roar_xcoder * state, void * buf, size_t len) { |
---|
| 108 | return -1; |
---|
| 109 | } |
---|
| 110 | |
---|
[2295] | 111 | #endif |
---|
| 112 | |
---|
| 113 | //ll |
---|