cardwo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. **********************************************************************
  3. * cardwo.c - PCM output HAL for emu10k1 driver
  4. * Copyright 1999, 2000 Creative Labs, Inc.
  5. *
  6. **********************************************************************
  7. *
  8. * Date Author Summary of changes
  9. * ---- ------ ------------------
  10. * October 20, 1999 Bertrand Lee base code release
  11. *
  12. **********************************************************************
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public
  25. * License along with this program; if not, write to the Free
  26. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  27. * USA.
  28. *
  29. **********************************************************************
  30. */
  31. #include <linux/poll.h>
  32. #include "hwaccess.h"
  33. #include "8010.h"
  34. #include "voicemgr.h"
  35. #include "cardwo.h"
  36. #include "audio.h"
  37. static u32 samplerate_to_linearpitch(u32 samplingrate)
  38. {
  39. samplingrate = (samplingrate << 8) / 375;
  40. return (samplingrate >> 1) + (samplingrate & 1);
  41. }
  42. static void query_format(struct emu10k1_wavedevice *wave_dev, struct wave_format *wave_fmt)
  43. {
  44. int i, j, do_passthrough = 0, is_ac3 = 0;
  45. struct emu10k1_card *card = wave_dev->card;
  46. struct woinst *woinst = wave_dev->woinst;
  47. if ((wave_fmt->channels > 2) && (wave_fmt->id != AFMT_S16_LE) && (wave_fmt->id != AFMT_U8))
  48. wave_fmt->channels = 2;
  49. if ((wave_fmt->channels < 1) || (wave_fmt->channels > WAVEOUT_MAXVOICES))
  50. wave_fmt->channels = 2;
  51. if (wave_fmt->channels == 2)
  52. woinst->num_voices = 1;
  53. else
  54. woinst->num_voices = wave_fmt->channels;
  55. if (wave_fmt->samplingrate >= 0x2ee00)
  56. wave_fmt->samplingrate = 0x2ee00;
  57. wave_fmt->passthrough = 0;
  58. do_passthrough = is_ac3 = 0;
  59. if (card->pt.selected)
  60. do_passthrough = 1;
  61. switch (wave_fmt->id) {
  62. case AFMT_S16_LE:
  63. wave_fmt->bitsperchannel = 16;
  64. break;
  65. case AFMT_U8:
  66. wave_fmt->bitsperchannel = 8;
  67. break;
  68. case AFMT_AC3:
  69. do_passthrough = 1;
  70. is_ac3 = 1;
  71. break;
  72. default:
  73. wave_fmt->id = AFMT_S16_LE;
  74. wave_fmt->bitsperchannel = 16;
  75. break;
  76. }
  77. if (do_passthrough) {
  78. /* currently only one waveout instance may use pass-through */
  79. if (woinst->state != WAVE_STATE_CLOSED ||
  80. card->pt.state != PT_STATE_INACTIVE ||
  81. (wave_fmt->samplingrate != 48000 && !is_ac3)) {
  82. DPF(2, "unable to set pass-through mode\n");
  83. } else if (USE_PT_METHOD1) {
  84. i = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.intr_gpr_name);
  85. j = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.enable_gpr_name);
  86. if (i < 0 || j < 0)
  87. DPF(2, "unable to set pass-through mode\n");
  88. else {
  89. wave_fmt->samplingrate = 48000;
  90. wave_fmt->channels = 2;
  91. card->pt.pos_gpr = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name,
  92. card->pt.pos_gpr_name);
  93. wave_fmt->passthrough = 1;
  94. card->pt.intr_gpr = i;
  95. card->pt.enable_gpr = j;
  96. card->pt.state = PT_STATE_INACTIVE;
  97. DPD(2, "is_ac3 is %d\n", is_ac3);
  98. card->pt.ac3data = is_ac3;
  99. wave_fmt->bitsperchannel = 16;
  100. }
  101. }else{
  102. DPF(2, "Using Passthrough Method 2\n");
  103. card->pt.enable_gpr = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name,
  104. card->pt.enable_gpr_name);
  105. wave_fmt->passthrough = 2;
  106. wave_fmt->bitsperchannel = 16;
  107. }
  108. }
  109. wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
  110. wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
  111. wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
  112. if (wave_fmt->channels == 2)
  113. wave_fmt->bytespervoicesample = wave_fmt->channels * wave_fmt->bytesperchannel;
  114. else
  115. wave_fmt->bytespervoicesample = wave_fmt->bytesperchannel;
  116. }
  117. static int get_voice(struct emu10k1_card *card, struct woinst *woinst, unsigned int voicenum)
  118. {
  119. struct emu_voice *voice = &woinst->voice[voicenum];
  120. /* Allocate voices here, if no voices available, return error. */
  121. voice->usage = VOICE_USAGE_PLAYBACK;
  122. voice->flags = 0;
  123. if (woinst->format.channels == 2)
  124. voice->flags |= VOICE_FLAGS_STEREO;
  125. if (woinst->format.bitsperchannel == 16)
  126. voice->flags |= VOICE_FLAGS_16BIT;
  127. if (emu10k1_voice_alloc(card, voice) < 0) {
  128. voice->usage = VOICE_USAGE_FREE;
  129. return -1;
  130. }
  131. /* Calculate pitch */
  132. voice->initial_pitch = (u16) (srToPitch(woinst->format.samplingrate) >> 8);
  133. voice->pitch_target = samplerate_to_linearpitch(woinst->format.samplingrate);
  134. DPD(2, "Initial pitch --> %#x\n", voice->initial_pitch);
  135. voice->startloop = (voice->mem.emupageindex << 12) /
  136. woinst->format.bytespervoicesample;
  137. voice->endloop = voice->startloop + woinst->buffer.size / woinst->format.bytespervoicesample;
  138. voice->start = voice->startloop;
  139. voice->params[0].volume_target = 0xffff;
  140. voice->params[0].initial_fc = 0xff;
  141. voice->params[0].initial_attn = 0x00;
  142. voice->params[0].byampl_env_sustain = 0x7f;
  143. voice->params[0].byampl_env_decay = 0x7f;
  144. if (voice->flags & VOICE_FLAGS_STEREO) {
  145. if (woinst->format.passthrough == 2) {
  146. voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PT];
  147. voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PT];
  148. voice->params[0].send_dcba = 0xff;
  149. voice->params[1].send_dcba = 0xff00;
  150. voice->params[0].send_hgfe = voice->params[1].send_hgfe=0;
  151. } else {
  152. voice->params[0].send_dcba = card->waveout.send_dcba[SEND_LEFT];
  153. voice->params[0].send_hgfe = card->waveout.send_hgfe[SEND_LEFT];
  154. voice->params[1].send_dcba = card->waveout.send_dcba[SEND_RIGHT];
  155. voice->params[1].send_hgfe = card->waveout.send_hgfe[SEND_RIGHT];
  156. if (woinst->device) {
  157. // /dev/dps1
  158. voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PCM1];
  159. voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PCM1];
  160. } else {
  161. voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PCM];
  162. voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PCM];
  163. }
  164. }
  165. voice->params[1].volume_target = 0xffff;
  166. voice->params[1].initial_fc = 0xff;
  167. voice->params[1].initial_attn = 0x00;
  168. voice->params[1].byampl_env_sustain = 0x7f;
  169. voice->params[1].byampl_env_decay = 0x7f;
  170. } else {
  171. if (woinst->num_voices > 1) {
  172. // Multichannel pcm
  173. voice->params[0].send_dcba=0xff;
  174. voice->params[0].send_hgfe=0;
  175. if (card->is_audigy) {
  176. voice->params[0].send_routing = 0x3f3f3f00 + card->mchannel_fx + voicenum;
  177. voice->params[0].send_routing2 = 0x3f3f3f3f;
  178. } else {
  179. voice->params[0].send_routing = 0xfff0 + card->mchannel_fx + voicenum;
  180. }
  181. } else {
  182. voice->params[0].send_dcba = card->waveout.send_dcba[SEND_MONO];
  183. voice->params[0].send_hgfe = card->waveout.send_hgfe[SEND_MONO];
  184. if (woinst->device) {
  185. voice->params[0].send_routing = card->waveout.send_routing[ROUTE_PCM1];
  186. voice->params[0].send_routing2 = card->waveout.send_routing2[ROUTE_PCM1];
  187. } else {
  188. voice->params[0].send_routing = card->waveout.send_routing[ROUTE_PCM];
  189. voice->params[0].send_routing2 = card->waveout.send_routing2[ROUTE_PCM];
  190. }
  191. }
  192. }
  193. DPD(2, "voice: startloop=%#x, endloop=%#x\n", voice->startloop, voice->endloop);
  194. emu10k1_voice_playback_setup(voice);
  195. return 0;
  196. }
  197. int emu10k1_waveout_open(struct emu10k1_wavedevice *wave_dev)
  198. {
  199. struct emu10k1_card *card = wave_dev->card;
  200. struct woinst *woinst = wave_dev->woinst;
  201. struct waveout_buffer *buffer = &woinst->buffer;
  202. unsigned int voicenum;
  203. u16 delay;
  204. DPF(2, "emu10k1_waveout_open()\n");
  205. for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
  206. if (emu10k1_voice_alloc_buffer(card, &woinst->voice[voicenum].mem, woinst->buffer.pages) < 0) {
  207. ERROR();
  208. emu10k1_waveout_close(wave_dev);
  209. return -1;
  210. }
  211. if (get_voice(card, woinst, voicenum) < 0) {
  212. ERROR();
  213. emu10k1_waveout_close(wave_dev);
  214. return -1;
  215. }
  216. }
  217. buffer->fill_silence = 0;
  218. buffer->silence_bytes = 0;
  219. buffer->silence_pos = 0;
  220. buffer->hw_pos = 0;
  221. buffer->free_bytes = woinst->buffer.size;
  222. delay = (48000 * woinst->buffer.fragment_size) /
  223. (woinst->format.samplingrate * woinst->format.bytespervoicesample);
  224. emu10k1_timer_install(card, &woinst->timer, delay);
  225. woinst->state = WAVE_STATE_OPEN;
  226. return 0;
  227. }
  228. void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev)
  229. {
  230. struct emu10k1_card *card = wave_dev->card;
  231. struct woinst *woinst = wave_dev->woinst;
  232. unsigned int voicenum;
  233. DPF(2, "emu10k1_waveout_close()\n");
  234. emu10k1_waveout_stop(wave_dev);
  235. emu10k1_timer_uninstall(card, &woinst->timer);
  236. for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
  237. emu10k1_voice_free(&woinst->voice[voicenum]);
  238. emu10k1_voice_free_buffer(card, &woinst->voice[voicenum].mem);
  239. }
  240. woinst->state = WAVE_STATE_CLOSED;
  241. }
  242. void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev)
  243. {
  244. struct emu10k1_card *card = wave_dev->card;
  245. struct woinst *woinst = wave_dev->woinst;
  246. struct pt_data *pt = &card->pt;
  247. DPF(2, "emu10k1_waveout_start()\n");
  248. if (woinst->format.passthrough == 2) {
  249. emu10k1_pt_setup(wave_dev);
  250. sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + pt->enable_gpr, 0, 1);
  251. pt->state = PT_STATE_PLAYING;
  252. }
  253. /* Actual start */
  254. emu10k1_voices_start(woinst->voice, woinst->num_voices, woinst->total_played);
  255. emu10k1_timer_enable(card, &woinst->timer);
  256. woinst->state |= WAVE_STATE_STARTED;
  257. }
  258. int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
  259. {
  260. struct emu10k1_card *card = wave_dev->card;
  261. struct woinst *woinst = wave_dev->woinst;
  262. unsigned int voicenum;
  263. u16 delay;
  264. DPF(2, "emu10k1_waveout_setformat()\n");
  265. if (woinst->state & WAVE_STATE_STARTED)
  266. return -1;
  267. query_format(wave_dev, format);
  268. if (woinst->format.samplingrate != format->samplingrate ||
  269. woinst->format.channels != format->channels ||
  270. woinst->format.bitsperchannel != format->bitsperchannel) {
  271. woinst->format = *format;
  272. if (woinst->state == WAVE_STATE_CLOSED)
  273. return 0;
  274. emu10k1_timer_uninstall(card, &woinst->timer);
  275. for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
  276. emu10k1_voice_free(&woinst->voice[voicenum]);
  277. if (get_voice(card, woinst, voicenum) < 0) {
  278. ERROR();
  279. emu10k1_waveout_close(wave_dev);
  280. return -1;
  281. }
  282. }
  283. delay = (48000 * woinst->buffer.fragment_size) /
  284. (woinst->format.samplingrate * woinst->format.bytespervoicesample);
  285. emu10k1_timer_install(card, &woinst->timer, delay);
  286. }
  287. return 0;
  288. }
  289. void emu10k1_waveout_stop(struct emu10k1_wavedevice *wave_dev)
  290. {
  291. struct emu10k1_card *card = wave_dev->card;
  292. struct woinst *woinst = wave_dev->woinst;
  293. DPF(2, "emu10k1_waveout_stop()\n");
  294. if (!(woinst->state & WAVE_STATE_STARTED))
  295. return;
  296. emu10k1_timer_disable(card, &woinst->timer);
  297. /* Stop actual voices */
  298. emu10k1_voices_stop(woinst->voice, woinst->num_voices);
  299. emu10k1_waveout_update(woinst);
  300. woinst->state &= ~WAVE_STATE_STARTED;
  301. }
  302. /**
  303. * emu10k1_waveout_getxfersize -
  304. *
  305. * gives the total free bytes on the voice buffer, including silence bytes
  306. * (basically: total_free_bytes = free_bytes + silence_bytes).
  307. *
  308. */
  309. void emu10k1_waveout_getxfersize(struct woinst *woinst, u32 *total_free_bytes)
  310. {
  311. struct waveout_buffer *buffer = &woinst->buffer;
  312. int pending_bytes;
  313. if (woinst->mmapped) {
  314. *total_free_bytes = buffer->free_bytes;
  315. return;
  316. }
  317. pending_bytes = buffer->size - buffer->free_bytes;
  318. buffer->fill_silence = (pending_bytes < (signed) buffer->fragment_size * 2) ? 1 : 0;
  319. if (pending_bytes > (signed) buffer->silence_bytes) {
  320. *total_free_bytes = (buffer->free_bytes + buffer->silence_bytes);
  321. } else {
  322. *total_free_bytes = buffer->size;
  323. buffer->silence_bytes = pending_bytes;
  324. if (pending_bytes < 0) {
  325. buffer->silence_pos = buffer->hw_pos;
  326. buffer->silence_bytes = 0;
  327. buffer->free_bytes = buffer->size;
  328. DPF(1, "buffer underrun\n");
  329. }
  330. }
  331. }
  332. /**
  333. * copy_block -
  334. *
  335. * copies a block of pcm data to a voice buffer.
  336. * Notice that the voice buffer is actually a set of disjointed memory pages.
  337. *
  338. */
  339. static void copy_block(void **dst, u32 str, u8 __user *src, u32 len)
  340. {
  341. unsigned int pg;
  342. unsigned int pgoff;
  343. unsigned int k;
  344. pg = str / PAGE_SIZE;
  345. pgoff = str % PAGE_SIZE;
  346. if (len > PAGE_SIZE - pgoff) {
  347. k = PAGE_SIZE - pgoff;
  348. if (__copy_from_user((u8 *)dst[pg] + pgoff, src, k))
  349. return;
  350. len -= k;
  351. while (len > PAGE_SIZE) {
  352. if (__copy_from_user(dst[++pg], src + k, PAGE_SIZE))
  353. return;
  354. k += PAGE_SIZE;
  355. len -= PAGE_SIZE;
  356. }
  357. if (__copy_from_user(dst[++pg], src + k, len))
  358. return;
  359. } else
  360. __copy_from_user((u8 *)dst[pg] + pgoff, src, len);
  361. }
  362. /**
  363. * copy_ilv_block -
  364. *
  365. * copies a block of pcm data containing n interleaved channels to n mono voice buffers.
  366. * Notice that the voice buffer is actually a set of disjointed memory pages.
  367. *
  368. */
  369. static void copy_ilv_block(struct woinst *woinst, u32 str, u8 __user *src, u32 len)
  370. {
  371. unsigned int pg;
  372. unsigned int pgoff;
  373. unsigned int voice_num;
  374. struct emu_voice *voice = woinst->voice;
  375. pg = str / PAGE_SIZE;
  376. pgoff = str % PAGE_SIZE;
  377. while (len) {
  378. for (voice_num = 0; voice_num < woinst->num_voices; voice_num++) {
  379. if (__copy_from_user((u8 *)(voice[voice_num].mem.addr[pg]) + pgoff, src, woinst->format.bytespervoicesample))
  380. return;
  381. src += woinst->format.bytespervoicesample;
  382. }
  383. len -= woinst->format.bytespervoicesample;
  384. pgoff += woinst->format.bytespervoicesample;
  385. if (pgoff >= PAGE_SIZE) {
  386. pgoff = 0;
  387. pg++;
  388. }
  389. }
  390. }
  391. /**
  392. * fill_block -
  393. *
  394. * fills a set voice buffers with a block of a given sample.
  395. *
  396. */
  397. static void fill_block(struct woinst *woinst, u32 str, u8 data, u32 len)
  398. {
  399. unsigned int pg;
  400. unsigned int pgoff;
  401. unsigned int voice_num;
  402. struct emu_voice *voice = woinst->voice;
  403. unsigned int k;
  404. pg = str / PAGE_SIZE;
  405. pgoff = str % PAGE_SIZE;
  406. if (len > PAGE_SIZE - pgoff) {
  407. k = PAGE_SIZE - pgoff;
  408. for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
  409. memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, k);
  410. len -= k;
  411. while (len > PAGE_SIZE) {
  412. pg++;
  413. for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
  414. memset(voice[voice_num].mem.addr[pg], data, PAGE_SIZE);
  415. len -= PAGE_SIZE;
  416. }
  417. pg++;
  418. for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
  419. memset(voice[voice_num].mem.addr[pg], data, len);
  420. } else {
  421. for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
  422. memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, len);
  423. }
  424. }
  425. /**
  426. * emu10k1_waveout_xferdata -
  427. *
  428. * copies pcm data to the voice buffer. Silence samples
  429. * previously added to the buffer are overwritten.
  430. *
  431. */
  432. void emu10k1_waveout_xferdata(struct woinst *woinst, u8 __user *data, u32 *size)
  433. {
  434. struct waveout_buffer *buffer = &woinst->buffer;
  435. struct voice_mem *mem = &woinst->voice[0].mem;
  436. u32 sizetocopy, sizetocopy_now, start;
  437. unsigned long flags;
  438. sizetocopy = min_t(u32, buffer->size, *size);
  439. *size = sizetocopy;
  440. if (!sizetocopy)
  441. return;
  442. spin_lock_irqsave(&woinst->lock, flags);
  443. start = (buffer->size + buffer->silence_pos - buffer->silence_bytes) % buffer->size;
  444. if (sizetocopy > buffer->silence_bytes) {
  445. buffer->silence_pos += sizetocopy - buffer->silence_bytes;
  446. buffer->free_bytes -= sizetocopy - buffer->silence_bytes;
  447. buffer->silence_bytes = 0;
  448. } else
  449. buffer->silence_bytes -= sizetocopy;
  450. spin_unlock_irqrestore(&woinst->lock, flags);
  451. sizetocopy_now = buffer->size - start;
  452. if (sizetocopy > sizetocopy_now) {
  453. sizetocopy -= sizetocopy_now;
  454. if (woinst->num_voices > 1) {
  455. copy_ilv_block(woinst, start, data, sizetocopy_now);
  456. copy_ilv_block(woinst, 0, data + sizetocopy_now * woinst->num_voices, sizetocopy);
  457. } else {
  458. copy_block(mem->addr, start, data, sizetocopy_now);
  459. copy_block(mem->addr, 0, data + sizetocopy_now, sizetocopy);
  460. }
  461. } else {
  462. if (woinst->num_voices > 1)
  463. copy_ilv_block(woinst, start, data, sizetocopy);
  464. else
  465. copy_block(mem->addr, start, data, sizetocopy);
  466. }
  467. }
  468. /**
  469. * emu10k1_waveout_fillsilence -
  470. *
  471. * adds samples of silence to the voice buffer so that we
  472. * don't loop over stale pcm data.
  473. *
  474. */
  475. void emu10k1_waveout_fillsilence(struct woinst *woinst)
  476. {
  477. struct waveout_buffer *buffer = &woinst->buffer;
  478. u32 sizetocopy, sizetocopy_now, start;
  479. u8 filldata;
  480. unsigned long flags;
  481. sizetocopy = buffer->fragment_size;
  482. if (woinst->format.bitsperchannel == 16)
  483. filldata = 0x00;
  484. else
  485. filldata = 0x80;
  486. spin_lock_irqsave(&woinst->lock, flags);
  487. buffer->silence_bytes += sizetocopy;
  488. buffer->free_bytes -= sizetocopy;
  489. buffer->silence_pos %= buffer->size;
  490. start = buffer->silence_pos;
  491. buffer->silence_pos += sizetocopy;
  492. spin_unlock_irqrestore(&woinst->lock, flags);
  493. sizetocopy_now = buffer->size - start;
  494. if (sizetocopy > sizetocopy_now) {
  495. sizetocopy -= sizetocopy_now;
  496. fill_block(woinst, start, filldata, sizetocopy_now);
  497. fill_block(woinst, 0, filldata, sizetocopy);
  498. } else {
  499. fill_block(woinst, start, filldata, sizetocopy);
  500. }
  501. }
  502. /**
  503. * emu10k1_waveout_update -
  504. *
  505. * updates the position of the voice buffer hardware pointer (hw_pos)
  506. * and the number of free bytes on the buffer (free_bytes).
  507. * The free bytes _don't_ include silence bytes that may have been
  508. * added to the buffer.
  509. *
  510. */
  511. void emu10k1_waveout_update(struct woinst *woinst)
  512. {
  513. u32 hw_pos;
  514. u32 diff;
  515. /* There is no actual start yet */
  516. if (!(woinst->state & WAVE_STATE_STARTED)) {
  517. hw_pos = woinst->buffer.hw_pos;
  518. } else {
  519. /* hw_pos in sample units */
  520. hw_pos = sblive_readptr(woinst->voice[0].card, CCCA_CURRADDR, woinst->voice[0].num);
  521. if(hw_pos < woinst->voice[0].start)
  522. hw_pos += woinst->buffer.size / woinst->format.bytespervoicesample - woinst->voice[0].start;
  523. else
  524. hw_pos -= woinst->voice[0].start;
  525. hw_pos *= woinst->format.bytespervoicesample;
  526. }
  527. diff = (woinst->buffer.size + hw_pos - woinst->buffer.hw_pos) % woinst->buffer.size;
  528. woinst->total_played += diff;
  529. woinst->buffer.free_bytes += diff;
  530. woinst->buffer.hw_pos = hw_pos;
  531. }