[0] | 1 | //output.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[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 | int output_buffer_init (struct roar_audio_info * info) { |
---|
[4814] | 29 | size_t size; |
---|
[0] | 30 | void * buf; |
---|
| 31 | |
---|
[4814] | 32 | g_output_buffer = NULL; |
---|
| 33 | g_input_buffer = NULL; |
---|
| 34 | g_output_buffer_len = 0; |
---|
[0] | 35 | |
---|
| 36 | size = ROAR_OUTPUT_CALC_OUTBUFSIZE(info); |
---|
| 37 | |
---|
| 38 | ROAR_DBG("output_buffer_init(*): output buffer size is %i", size); |
---|
| 39 | |
---|
[4230] | 40 | if ( (buf = roar_mm_malloc(size)) == NULL ) |
---|
[0] | 41 | return -1; |
---|
| 42 | |
---|
| 43 | g_output_buffer = buf; |
---|
| 44 | g_output_buffer_len = size; |
---|
| 45 | |
---|
[4814] | 46 | if ( (buf = roar_mm_malloc(size)) == NULL ) { |
---|
| 47 | g_output_buffer = NULL; |
---|
| 48 | g_output_buffer_len = 0; |
---|
| 49 | roar_mm_free(g_output_buffer); |
---|
| 50 | return -1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | g_input_buffer = buf; |
---|
| 54 | |
---|
[0] | 55 | ROAR_DBG("output_buffer_init(*): output buffer is at %p", buf); |
---|
| 56 | |
---|
[4814] | 57 | memlock_register(MEMLOCK_LOW, g_output_buffer, size); |
---|
| 58 | memlock_register(MEMLOCK_LOW, g_input_buffer, size); |
---|
[57] | 59 | |
---|
[0] | 60 | output_buffer_reinit(); |
---|
| 61 | |
---|
| 62 | return 0; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | int output_buffer_reinit (void) { |
---|
| 66 | |
---|
| 67 | if ( g_output_buffer != NULL ) |
---|
| 68 | memset(g_output_buffer, 0, g_output_buffer_len); |
---|
| 69 | |
---|
| 70 | return 0; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | int output_buffer_free (void) { |
---|
| 74 | ROAR_DBG("output_buffer_init(*): freeing output buffer at %p", g_output_buffer); |
---|
| 75 | |
---|
[4230] | 76 | if ( g_output_buffer != NULL ) |
---|
| 77 | roar_mm_free(g_output_buffer); |
---|
[0] | 78 | |
---|
[4814] | 79 | if ( g_input_buffer != NULL ) |
---|
| 80 | roar_mm_free(g_input_buffer); |
---|
| 81 | |
---|
[0] | 82 | g_output_buffer = NULL; |
---|
[4814] | 83 | g_input_buffer = NULL; |
---|
[0] | 84 | g_output_buffer_len = 0; |
---|
| 85 | |
---|
| 86 | return 0; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | //ll |
---|