Example #1
0
static void
DCAUD_PlayDevice(_THIS)
{
    SDL_AudioSpec *spec = &this->spec;
    unsigned int offset;

    if (this->hidden->playing) {
        /* wait */
        while (aica_get_pos(0) / spec->samples == this->hidden->nextbuf) {
            thd_pass();
        }
    }

    offset = this->hidden->nextbuf * spec->size;
    this->hidden->nextbuf ^= 1;
    /* Write the audio data, checking for EAGAIN on broken audio drivers */
    if (spec->channels == 1) {
        spu_memload(this->hidden->leftpos + offset, this->hidden->mixbuf,
                    this->hidden->mixlen);
    } else {
        offset /= 2;
        if ((this->spec.format & 255) == 8) {
            spu_memload_stereo8(this->hidden->leftpos + offset,
                                this->hidden->rightpos + offset,
                                this->hidden->mixbuf, this->hidden->mixlen);
        } else {
            spu_memload_stereo16(this->hidden->leftpos + offset,
                                 this->hidden->rightpos + offset,
                                 this->hidden->mixbuf, this->hidden->mixlen);
        }
    }

    if (!this->hidden->playing) {
        int mode;
        this->hidden->playing = 1;
        mode = (spec->format == AUDIO_S8) ? SM_8BIT : SM_16BIT;
        if (spec->channels == 1) {
            aica_play(0, mode, this->hidden->leftpos, 0,
                      spec->samples * 2, spec->freq, 255, 128, 1);
        } else {
            aica_play(0, mode, this->hidden->leftpos, 0,
                      spec->samples * 2, spec->freq, 255, 0, 1);
            aica_play(1, mode, this->hidden->rightpos, 0,
                      spec->samples * 2, spec->freq, 255, 255, 1);
        }
    }
}
Example #2
0
static void audio_write(AVCodecContext *audio, void *buf, size_t size) {
	
	if(!aud->channels) {
		return;
	}
	
	int nsamples = size/(aud->channels*aud->bytes);
	int writepos = 0;
	int curpos =0;

	if (!aud->playing) {

		aud->sampsize = (65535)/nsamples*nsamples;
		//printf("audio size=%d n=%d sampsize=%d\n",size,nsamples,aud->sampsize);
		aud->leftbuf  = 0x11000;//AICA_RAM_START;//
		aud->rightbuf = 0x11000/*AICA_RAM_START*/ + aud->sampsize*aud->bytes;
		aud->writepos = 0;
	} else {
		//curpos = aica_get_pos(0);
		//if (writepos < curpos && curpos < writepos+nsamples) {
			//printf("audio:wait");
		//}
		/*
		while(aud->writepos < curpos && curpos < aud->writepos + nsamples) {
			curpos = aica_get_pos(0);
			//timer_spin_sleep(50);
			//thd_sleep(50);
			//thd_pass();
			thd_sleep(10);
			//timer_spin_sleep(2);
		}
		*/
		writepos = aud->writepos;
		curpos = aica_get_pos(0);

		do {
			curpos = aica_get_pos(0);
		} while(writepos < curpos && curpos < writepos + nsamples);
		//audio_end();
	}
	
	writepos = aud->writepos * aud->bytes;
	
	if (aud->channels == 1) {
		spu_memload(aud->leftbuf + writepos, buf, size);
		//spu_memload_mono16(aud->leftbuf + writepos, buf, size);
	} else {
		spu_memload_stereo16(aud->leftbuf + writepos, aud->rightbuf + writepos, buf, size);
	}

	aud->writepos += nsamples;
	
	if (aud->writepos >= aud->sampsize) {
		aud->writepos = 0;
	}

	if (!aud->playing) {
		
		int mode;
		int vol = 255;
		aud->playing = 1;
		mode = (aud->bits == 16) ? SM_16BIT : SM_8BIT;
		
		if (aud->channels == 1) {
			aica_play(0,mode,aud->leftbuf,0,aud->sampsize,aud->rate,vol,128,1);
		} else {
		//	printf("%d %d\n",aud->sampsize,aud->rate);
			aica_play(0,mode,aud->leftbuf ,0,aud->sampsize,aud->rate,vol,  0,1);
			aica_play(1,mode,aud->rightbuf,0,aud->sampsize,aud->rate,vol,255,1);
		}
	}
}