[2945] | 1 | //waveform.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 |
---|
[2945] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2945] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
[4820] | 28 | static int waveform_init_recbridge (void) { |
---|
| 29 | struct roar_stream * s; |
---|
| 30 | |
---|
| 31 | if ( (g_waveform_recbridge.stream = streams_new()) == -1 ) |
---|
| 32 | return -1; |
---|
| 33 | |
---|
| 34 | client_stream_add(g_self_client, g_waveform_recbridge.stream); |
---|
| 35 | |
---|
| 36 | streams_get(g_waveform_recbridge.stream, &(g_waveform_recbridge.ss)); |
---|
| 37 | |
---|
| 38 | s = ROAR_STREAM(g_waveform_recbridge.ss); |
---|
| 39 | |
---|
| 40 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 41 | |
---|
| 42 | s->pos_rel_id = g_waveform_mixer.stream; |
---|
| 43 | |
---|
| 44 | if ( streams_set_dir(g_waveform_recbridge.stream, ROAR_DIR_BRIDGE, 1) == -1 ) { |
---|
| 45 | streams_delete(g_waveform_recbridge.stream); |
---|
| 46 | g_waveform_recbridge.stream = -1; |
---|
| 47 | g_waveform_recbridge.ss = NULL; |
---|
| 48 | return -1; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | streams_set_name(g_waveform_recbridge.stream, "Record Bridge"); |
---|
| 52 | |
---|
| 53 | streams_set_flag(g_waveform_recbridge.stream, ROAR_FLAG_PRIMARY); |
---|
| 54 | streams_set_flag(g_waveform_recbridge.stream, ROAR_FLAG_SYNC); |
---|
| 55 | streams_set_flag(g_waveform_recbridge.stream, ROAR_FLAG_MUTE); |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
[2945] | 60 | int waveform_init (void) { |
---|
[2946] | 61 | struct roar_stream_server * ss; |
---|
| 62 | struct roar_stream * s; |
---|
[3215] | 63 | int i; |
---|
[3558] | 64 | char cmap[ROAR_MAX_CHANNELS]; |
---|
[2946] | 65 | |
---|
[4820] | 66 | // setup mixer: |
---|
[2946] | 67 | if ( (g_waveform_mixer.stream = add_mixer(ROAR_SUBSYS_WAVEFORM, _MIXER_NAME("Waveform"), &ss)) == -1 ) |
---|
| 68 | return -1; |
---|
| 69 | |
---|
[2947] | 70 | g_waveform_mixer.ss = ss; |
---|
| 71 | |
---|
[2946] | 72 | s = ROAR_STREAM(ss); |
---|
| 73 | |
---|
| 74 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 75 | |
---|
[3558] | 76 | roardsp_chanlist_init(cmap, s->info.channels, ROARDSP_CHANLIST_MAP_ROARAUDIO); |
---|
| 77 | streams_set_map(g_waveform_mixer.stream, cmap, s->info.channels); |
---|
[3547] | 78 | |
---|
[2946] | 79 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
| 80 | |
---|
[4820] | 81 | |
---|
| 82 | // setup Record Bridge: |
---|
| 83 | if ( waveform_init_recbridge() == -1 ) { |
---|
| 84 | ROAR_WARN("waveform_init(void): Can not setup Record Bridge."); |
---|
| 85 | streams_delete(g_waveform_mixer.stream); |
---|
| 86 | g_waveform_mixer.stream = -1; |
---|
| 87 | g_waveform_mixer.ss = NULL; |
---|
| 88 | return -1; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | streams_set_mixer_stream(g_waveform_recbridge.stream, g_waveform_mixer.stream); |
---|
| 92 | |
---|
| 93 | // attach all waveform streams to the mixer. |
---|
[3215] | 94 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 95 | if ( g_streams[i] != NULL ) { |
---|
| 96 | if ( streams_get_subsys(i) == ROAR_SUBSYS_WAVEFORM ) { |
---|
| 97 | streams_set_mixer_stream(i, g_waveform_mixer.stream); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
[2945] | 102 | return 0; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | int waveform_free (void) { |
---|
| 106 | return 0; |
---|
| 107 | } |
---|
| 108 | |
---|
[4820] | 109 | int waveform_update_inputs (void) { |
---|
| 110 | struct roar_buffer * buf; |
---|
[4821] | 111 | void * bufdata; |
---|
[4815] | 112 | |
---|
| 113 | // read recorded data...: |
---|
| 114 | if ( streams_recsource_id != -1 ) { |
---|
[4821] | 115 | if ( streams_get_outputbuffer(streams_recsource_id, &bufdata, g_input_buffer_len) == -1 ) { |
---|
| 116 | ROAR_WARN("waveform_update_mixer(void): can not request output buffer for record stream %i.", streams_recsource_id); |
---|
| 117 | } else { |
---|
| 118 | if ( streams_fill_mixbuffer2(streams_recsource_id, g_sa) == -1 ) { |
---|
| 119 | ROAR_WARN("waveform_update_mixer(void): can not fill output buffer for record stream %i.", streams_recsource_id); |
---|
[4819] | 120 | } else { |
---|
[4821] | 121 | memcpy(g_input_buffer, bufdata, g_input_buffer_len); |
---|
[4819] | 122 | } |
---|
[4815] | 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
[4820] | 126 | if ( !(g_waveform_recbridge.ss->flags & (ROAR_FLAG_PAUSE|ROAR_FLAG_MUTE)) ) { |
---|
| 127 | if ( roar_buffer_new_no_ma(&buf, g_input_buffer_len, g_input_buffer) == -1 ) { |
---|
| 128 | ROAR_ERR("waveform_update_inputs(void): Can not create a new buffer object for Record Bridge. Bad."); |
---|
| 129 | return -1; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | if ( stream_add_buffer(g_waveform_recbridge.stream, buf) == -1 ) { |
---|
| 133 | ROAR_ERR("waveform_update_inputs(void): Can not attach a new buffer object to the Record Bridge. Bad."); |
---|
| 134 | roar_buffer_free(buf); |
---|
| 135 | return -1; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | return 0; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | int waveform_update_mixer (void) { |
---|
[2949] | 143 | if ( streams_get_flag(g_waveform_mixer.stream, ROAR_FLAG_MUTE) == 1 ) { |
---|
| 144 | memset(g_output_buffer, 0, (g_sa->bits*ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels)/8); |
---|
| 145 | return 0; |
---|
| 146 | } |
---|
| 147 | |
---|
[4288] | 148 | if ( need_vol_change(ROAR_STREAM(g_waveform_mixer.ss)->info.channels, &(g_waveform_mixer.ss->mixer)) ) { |
---|
| 149 | roar_amp_pcm(g_output_buffer, g_sa->bits, g_output_buffer, |
---|
| 150 | ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa->channels, |
---|
| 151 | &(g_waveform_mixer.ss->mixer)); |
---|
| 152 | } |
---|
[2947] | 153 | |
---|
[4288] | 154 | streams_ltm_calc(g_waveform_mixer.stream, &(ROAR_STREAM(g_waveform_mixer.ss)->info), g_output_buffer, (g_sa->bits*ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels)/8); |
---|
[2947] | 155 | |
---|
| 156 | return 0; |
---|
| 157 | } |
---|
| 158 | |
---|
[2945] | 159 | //ll |
---|