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