Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. /*
  2. ao_gekko.c - MPlayer audio driver for Wii
  3.  
  4. Copyright (C) 2008 dhewg
  5. Improved by Tantric & rodries
  6.  
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2 of the License, or (at your option) any later version.
  11.  
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Lesser General Public
  18. License along with this library; if not, write to the
  19. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. Boston, MA 02110-1301 USA.
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. #include "config.h"
  28. #include "libaf/af_format.h"
  29. #include "audio_out.h"
  30. #include "audio_out_internal.h"
  31. #include "mp_msg.h"
  32. #include "help_mp.h"
  33.  
  34. #include <ogcsys.h>
  35. #include "osdep/plat_gekko.h"
  36.  
  37. static ao_info_t info = {
  38. "gekko audio output",
  39. "gekko",
  40. "Team Twiizers",
  41. ""
  42. };
  43.  
  44. LIBAO_EXTERN(gekko)
  45.  
  46. #define SFX_BUFFER_SIZE (8*1024)
  47. #define SFX_BUFFERS 32
  48. #define BUFFERSIZE ((SFX_BUFFERS-1)*SFX_BUFFER_SIZE)
  49.  
  50. static u8 buffer[SFX_BUFFERS][SFX_BUFFER_SIZE] ATTRIBUTE_ALIGN(32);
  51. static u8 buffer_fill = 0;
  52. static u8 buffer_play = 0;
  53. static bool playing = false;
  54. static unsigned int bytes_buffered = 0;
  55.  
  56. static void switch_buffers() {
  57.  
  58. if(bytes_buffered<=0)
  59. {
  60. playing = false;
  61. AUDIO_StopDMA();
  62. return;
  63. }
  64.  
  65. DCFlushRange(buffer[buffer_play], SFX_BUFFER_SIZE);
  66. AUDIO_InitDMA((u32) buffer[buffer_play], SFX_BUFFER_SIZE);
  67. AUDIO_StartDMA();
  68. playing = true;
  69. bytes_buffered -= SFX_BUFFER_SIZE;
  70. buffer_play = (buffer_play + 1) % SFX_BUFFERS;
  71.  
  72. }
  73.  
  74. static int control(int cmd, void *arg) {
  75. //mp_msg(MSGT_AO, MSGL_ERR, "[AOGEKKO]: control %d\n", cmd);
  76.  
  77. return CONTROL_UNKNOWN;
  78. }
  79.  
  80. void reinit_audio() // for newgui
  81. {
  82. AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
  83. AUDIO_RegisterDMACallback(switch_buffers);
  84. }
  85.  
  86. static int init(int rate, int channels, int format, int flags) {
  87. u8 i;
  88.  
  89. AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
  90. AUDIO_RegisterDMACallback(switch_buffers);
  91.  
  92. ao_data.buffersize = SFX_BUFFER_SIZE * SFX_BUFFERS;
  93. ao_data.outburst = SFX_BUFFER_SIZE;
  94. ao_data.channels = 2;
  95. ao_data.samplerate = 48000;
  96. ao_data.format = AF_FORMAT_S16_BE;
  97. ao_data.bps = 192000;
  98.  
  99. for (i = 0; i < SFX_BUFFERS; ++i) {
  100. memset(buffer[i], 0, SFX_BUFFER_SIZE);
  101. DCFlushRange(buffer[i], SFX_BUFFER_SIZE);
  102. }
  103.  
  104. buffer_fill = 0;
  105. buffer_play = 0;
  106.  
  107. bytes_buffered = 0;
  108.  
  109. return 1;
  110. }
  111.  
  112. static void reset(void) {
  113. u8 i;
  114.  
  115. AUDIO_StopDMA();
  116.  
  117. for (i = 0; i < SFX_BUFFERS; ++i) {
  118. memset(buffer[i], 0, SFX_BUFFER_SIZE);
  119. DCFlushRange(buffer[i], SFX_BUFFER_SIZE);
  120. }
  121.  
  122. buffer_fill = 0;
  123. buffer_play = 0;
  124.  
  125. bytes_buffered = 0;
  126.  
  127. playing = false;
  128.  
  129. }
  130.  
  131. static void uninit(int immed) {
  132. reset();
  133.  
  134. AUDIO_RegisterDMACallback(NULL);
  135. }
  136.  
  137. static void audio_pause(void) {
  138. AUDIO_StopDMA();
  139. playing = false;
  140. }
  141.  
  142. static void audio_resume(void) {
  143. switch_buffers();
  144. }
  145.  
  146. static int get_space(void) {
  147. return BUFFERSIZE-bytes_buffered;
  148. }
  149.  
  150. #define SWAP(x) ((x>>16)|(x<<16))
  151. static void copy_swap_channels(u32 *d, u32 *s, int len)
  152. {
  153. int n;
  154.  
  155. len=len/4;
  156. for(n=0;n<len;n++) d[n] = SWAP(s[n]);
  157. }
  158.  
  159. static int play(void* data, int len, int flags) {
  160. int bl, ret = 0;
  161. u8 *s = (u8 *) data;
  162.  
  163. while ((len > 0) && (get_space()>SFX_BUFFER_SIZE)) {
  164. bl = len;
  165. if (bl > SFX_BUFFER_SIZE)
  166. bl = SFX_BUFFER_SIZE;
  167.  
  168. if(bl<SFX_BUFFER_SIZE) break;
  169.  
  170. copy_swap_channels((u32*)buffer[buffer_fill], (u32*)s, SFX_BUFFER_SIZE);
  171. buffer_fill = (buffer_fill + 1) % SFX_BUFFERS;
  172. bytes_buffered += bl;
  173.  
  174. len -= bl;
  175. s += bl;
  176. ret += bl;
  177. }
  178. if (!playing)
  179. switch_buffers();
  180.  
  181.  
  182. return ret;
  183. }
  184.  
  185. static float get_delay(void) {
  186.  
  187. if (playing)
  188. return (bytes_buffered + AUDIO_GetDMABytesLeft()) / 192000.0f;
  189.  
  190. return bytes_buffered / 192000.0f;
  191. }
Add Comment
Please, Sign In to add comment