Exemplo n.º 1
0
void
SDL_sound_handler::openAudio()
{
    if ( _audioOpened ) return; // nothing to do

    // This is our sound settings
    audioSpec.freq = 44100;

    // Each sample is a signed 16-bit audio in system-endian format
    audioSpec.format = AUDIO_S16SYS; 

    // We want to be pulling samples for 2 channels:
    // {left,right},{left,right},...
    audioSpec.channels = 2;

    audioSpec.callback = SDL_sound_handler::sdl_audio_callback;

    audioSpec.userdata = this;

    //512 - not enough for  videostream
    audioSpec.samples = 2048;   

    if (SDL_OpenAudio(&audioSpec, NULL) < 0 ) {
            boost::format fmt = boost::format(
                _("Unable to open SDL audio: %s"))
                % SDL_GetError();
        throw SoundException(fmt.str());
    }

    _audioOpened = true;
}
Exemplo n.º 2
0
void TempFigure::show(SDL_Rect* otherCamera) {
   if (marker == INACTIVE)
      return;
   else if (marker == REMOVE) {
      bool animationDone = true;
      marker = INACTIVE;

      if (animationDone) {
         if (Mix_PlayChannel(-1, scratch.getMix_Chunk(), 0) < 0) {
            printf("Mix_PlayChannel: %s\n", Mix_GetError());
            throw SoundException();
         }
      }
   }
   else if (marker == ACTIVE) {
      if (numClips > 0) {
         if (v.x < 0) {
            status = LEFT;
            animationFrame += AFVALUE;
         }
         else if (v.x > 0) {
            status = RIGHT;
            animationFrame += AFVALUE;
         }
         else
            animationFrame = 0;

         if (animationFrame >= numClips)
            animationFrame = 0;

         if (leader) {
            if (status == LEFT)
               applySurface((int) p.x - camera->x, (int) p.y - camera->y,
                     *image, screen, &cl[static_cast<int>(animationFrame)]);
            else if (status == RIGHT)
               applySurface((int) p.x - camera->x, (int) p.y - camera->y,
                     *image, screen, &cr[static_cast<int>(animationFrame)]);

            if (particleEffects)
               showParticles(camera);
         }
         else {
            if (status == LEFT)
               applySurface((int) p.x - otherCamera->x,
                     (int) p.y - otherCamera->y, *image, screen,
                     &cl[static_cast<int>(animationFrame)]);
            else if (status == RIGHT)
               applySurface((int) p.x - otherCamera->x,
                     (int) p.y - otherCamera->y, *image, screen,
                     &cr[static_cast<int>(animationFrame)]);

            if (particleEffects)
               showParticles(otherCamera);
         }
      }
   }
   else
      throw InvalidMarkerException();
}
Exemplo n.º 3
0
/* public */
WAVWriter::WAVWriter(const std::string& wavefile)
{
        file_stream.open(wavefile.c_str());
        if (file_stream.fail()) {
            boost::format fmt = boost::format(_("Unable to write file %1%"))
                % wavefile;
            throw SoundException(fmt.str());
        } 
        else {
            write_wave_header(file_stream);
            std::cout << "# Created 44100 16Mhz stereo wave file:\n" <<
                    "AUDIOFILE=" << wavefile << std::endl;
        }
}
Exemplo n.º 4
0
int
AOS4_sound_handler::audioTask()
{
	uint32 sigMask;
	unsigned long clockAdvance = 40;
	unsigned int nSamples = (441*clockAdvance) / 10;
	unsigned int toFetch = nSamples*2;
	boost::int16_t samples[AHI_BUF_SIZE];

	_closing = false;

	AHIDevice = -1;

	PlayBuffer[0] = (UBYTE*)IExec->AllocMem(BUFSIZE, MEMF_SHARED|MEMF_CLEAR);
	PlayBuffer[1] = (UBYTE*)IExec->AllocMem(BUFSIZE, MEMF_SHARED|MEMF_CLEAR);
	if (!PlayBuffer[0] || !PlayBuffer[1])
	{
        log_error(_("AOS4: Unable to allocate memory for audio buffer!"));
  	    throw SoundException("AOS4: Unable to allocate memory for audio buffer!");
	}

	if ((AHImp=(struct MsgPort*) IExec->AllocSysObjectTags(ASOT_PORT, TAG_DONE)) != NULL)
	{
		if ((AHIio=(struct AHIRequest *) IExec->AllocSysObjectTags(ASOT_IOREQUEST,
																	ASOIOR_Size, 		sizeof(struct AHIRequest),
																	ASOIOR_ReplyPort, 	AHImp,
																	TAG_DONE)) != NULL)
		{
			AHIio->ahir_Version = 4;
			AHIDevice = IExec->OpenDevice(AHINAME, 0, (struct IORequest *)AHIio, 0);
			if (AHIDevice)
			{
				if (AHImp) IExec->FreeSysObject(ASOT_PORT, 		AHImp); AHImp = 0;
				if (AHIio) IExec->FreeSysObject(ASOT_IOREQUEST, (struct IORequest *)AHIio); AHIio = 0;
				if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0;
				if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0;

    	        log_error(_("AOS4: Unable to open AHI Device!"));
	    	    throw SoundException("AOS4: Unable to open AHI Device!");
			}
			IAHI = (struct AHIIFace *) IExec->GetInterface( (struct Library *) AHIio->ahir_Std.io_Device, "main", 1, NULL );
		}
		else
		{
			if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0;
			if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0;
			if (AHImp) IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0;
            log_error(_("AOS4: Unable to CreateIORequest!"));
	        throw SoundException("AOS4: Unable to CreateIORequest!");
		}
	}
	else
	{
		if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0;
		if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0;
		log_error(_("AOS4: Unable to CreateMsgPort for AHI Device!"));
		throw SoundException("AOS4: Unable to CreateMsgPort for AHI Device!");
	}

	AHIiocopy = IExec->AllocSysObjectTags(ASOT_IOREQUEST,ASOIOR_Duplicate,AHIio,TAG_DONE);
	if(! AHIiocopy)
	{
		if (AHImp) IExec->FreeSysObject(ASOT_PORT, 		AHImp); AHImp = 0;
		if (AHIio) IExec->FreeSysObject(ASOT_IOREQUEST, (struct IORequest *)AHIio); AHIio = 0;
		if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0;
		if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0;
		log_error(_("AOS4: Not enough memory for AHIiocopy!"));
		throw SoundException("AOS4: Not enough memory for AHIiocopy!");
	}

	AHICurBuf = 0;

	Buffer = 0;
	BufferPointer = PlayBuffer[0];
	BufferFill = 0;

	AHIReqSent[0] = false;
	AHIReqSent[1] = false;

	AHIios[0]=AHIio;
	AHIios[1]=(AHIRequest*)AHIiocopy;

	log_debug(_("AOS4: audioTask:Initialize timer.."));
	TimerInit();

	log_debug(_("AOS4: audioTask:Starting Timer.."));
	TimerReset(RESET_TIME);
    while (true)
    {
		sigMask = SIGBREAKF_CTRL_C | _timerSig;

		uint32 sigGot = IExec->Wait(sigMask);

	    if (sigGot & SIGBREAKF_CTRL_C)
	    {
			_closing = true;
			log_debug(_("AOS4: Closing Audio Thread.."));
			break;
		}
		if (sigGot & _timerSig)
    	{
			IExec->GetMsg(_port);
			if (!sound_handler::isPaused())
			{
				while (toFetch && !_closing)
				{
					unsigned int n = std::min(toFetch, AHI_BUF_SIZE);
					if (!_closing) fetchSamples((boost::int16_t*)&samples, n);
					toFetch -= n;
				}
				toFetch = nSamples*2;
			}
			if (!_closing) TimerReset(RESET_TIME);
	    }
	}

	log_debug(_("AOS4: Cleaning Audio Stuff.."));

	if (AHIios[0])
	{
		if (!IExec->CheckIO((struct IORequest *) AHIios[0]))
		{
			IExec->AbortIO((struct IORequest *) AHIios[0]);
			IExec->WaitIO((struct IORequest *) AHIios[0]);
		}
	}

	if(AHIios[1])
	{ // Only if the second request was started
		if (!IExec->CheckIO((struct IORequest *) AHIios[1]))
		{
    		IExec->AbortIO((struct IORequest *) AHIios[1]);
    		IExec->WaitIO((struct IORequest *) AHIios[1]);
		}
	}


	if(!AHIDevice)
		if (AHIio) 	IExec->CloseDevice((struct IORequest *)AHIio);

	if (AHIio) 		IExec->FreeSysObject(ASOT_IOREQUEST,(struct IORequest *)AHIio); AHIio = 0;
	if (AHIiocopy) 	IExec->FreeMem(AHIiocopy,sizeof(struct AHIRequest)); AHIiocopy = 0;

  	if (AHImp)		IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0;

	if (IAHI) 		IExec->DropInterface((struct Interface*) IAHI); IAHI = 0;

	if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0;
	if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0;

	log_debug(_("AOS4: Exit Audio Thread.."));

	log_debug(_("AOS4: audioTask:Close timer.."));
	TimerExit();
    return(RETURN_OK);
}