[0] | 1 | //output.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 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. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include "roard.h" |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | void * g_output_buffer; |
---|
| 30 | unsigned int g_output_buffer_len; |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | int output_buffer_init (struct roar_audio_info * info) { |
---|
| 34 | size_t size; // = ROAR_OUTPUT_BUFFER_SAMPLES; |
---|
| 35 | void * buf; |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | size *= info->channels; |
---|
| 39 | size *= info->bits / 8; |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | size = ROAR_OUTPUT_CALC_OUTBUFSIZE(info); |
---|
| 43 | |
---|
| 44 | ROAR_DBG("output_buffer_init(*): output buffer size is %i", size); |
---|
| 45 | |
---|
| 46 | if ( (buf = malloc(size)) == NULL ) |
---|
| 47 | return -1; |
---|
| 48 | |
---|
| 49 | g_output_buffer = buf; |
---|
| 50 | g_output_buffer_len = size; |
---|
| 51 | |
---|
| 52 | ROAR_DBG("output_buffer_init(*): output buffer is at %p", buf); |
---|
| 53 | |
---|
[57] | 54 | #ifdef ROAR_HAVE_MLOCK |
---|
| 55 | ROAR_MLOCK(buf, size); |
---|
| 56 | #endif |
---|
| 57 | |
---|
[0] | 58 | output_buffer_reinit(); |
---|
| 59 | |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | int output_buffer_reinit (void) { |
---|
| 64 | |
---|
| 65 | if ( g_output_buffer != NULL ) |
---|
| 66 | memset(g_output_buffer, 0, g_output_buffer_len); |
---|
| 67 | |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | int output_buffer_free (void) { |
---|
| 72 | ROAR_DBG("output_buffer_init(*): freeing output buffer at %p", g_output_buffer); |
---|
| 73 | |
---|
| 74 | if ( g_output_buffer ) |
---|
| 75 | free(g_output_buffer); |
---|
| 76 | |
---|
| 77 | g_output_buffer = NULL; |
---|
| 78 | g_output_buffer_len = 0; |
---|
| 79 | |
---|
| 80 | return 0; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | int output_buffer_flush (DRIVER_USERDATA_T inst, int driver) { |
---|
| 84 | ROAR_DBG("output_buffer_init(*): flushing output buffer"); |
---|
| 85 | |
---|
| 86 | return driver_write(inst, driver, g_output_buffer, g_output_buffer_len); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | //ll |
---|