Ejemplo n.º 1
0
/* Get a block of data from the input.  If buffer is NULL, just return the amount
 * that would be read. */
int RageSound::GetData( char *pBuffer, int iFrames )
{
	if( m_Param.m_LengthSeconds != -1 )
	{
		/* We have a length; only read up to the end. */
		const float LastSecond = m_Param.m_StartSecond + m_Param.m_LengthSeconds;
		int FramesToRead = int(LastSecond*samplerate()) - m_iDecodePosition;

		/* If it's negative, we're past the end, so cap it at 0. Don't read
		 * more than size. */
		iFrames = clamp( FramesToRead, 0, iFrames );
	}

	int iGot;
	if( m_iDecodePosition < 0 )
	{
		/* We havn't *really* started playing yet, so just feed silence.  How
		 * many more bytes of silence do we need? */
		iGot = -m_iDecodePosition;
		iGot = min( iGot, iFrames );
		if( pBuffer )
			memset( pBuffer, 0, iGot*framesize );
	} else {
		/* Feed data out of our streaming buffer. */
		ASSERT( m_pSource );
		iGot = min( int(m_DataBuffer.num_readable()/framesize), iFrames );
		if( pBuffer )
			m_DataBuffer.read( pBuffer, iGot*framesize );
	}

	return iGot;
}
TInt COpenMAXALTestModule::al_audioiodevcapitf_QuerySampleFormatsSupported( CStifItemParser& aItem )
    {
    TInt status(KErrNone);
    XAresult res;
    TInt sizeArr(0);
    TUint deviceId(0);
    TInt samplerate(0);
    XAuint32 devId(0);
    XAmilliHertz samplingrate;
    XAint32 deviceIdArr[20];
    XAint32 numSampleRates(0);
    
    status = aItem.GetNextInt(deviceId);
    if(!status)
        {
        devId = deviceId;
        status = aItem.GetNextInt(samplerate);
        if(!status)
            {
            samplingrate = samplerate;
            status = aItem.GetNextInt(sizeArr);
            if(!status)
                {
                numSampleRates = sizeArr;
                if(m_AIODevCapItf)
                    {
                    res = (*m_AIODevCapItf)->QuerySampleFormatsSupported(
                            m_AIODevCapItf, devId, samplingrate, deviceIdArr, &numSampleRates);
                    status = res;
                    }
                else
                    {
                    status = KErrNotFound;
                    }        
                }
            else
                {
                if(m_AIODevCapItf)
                    {
                    res = (*m_AIODevCapItf)->QuerySampleFormatsSupported(
                            m_AIODevCapItf, devId, samplingrate, NULL, &numSampleRates);
                    status = res;
                    }
                else
                    {
                    status = KErrNotFound;
                    }        
                }
            }
        else
            {
            status = KErrGeneral;
            }
        }
    else
        {
        status = KErrGeneral;
        }
    return status;
    }
Ejemplo n.º 3
0
void AsiHpiDevice::MakeFormat(struct hpi_format *fmt,uint16_t hfmt)
{
    memset(fmt,0,sizeof(hpi_format));
    fmt->dwSampleRate=samplerate();
    fmt->wChannels=channels();
    fmt->wFormat=hfmt;
}
Ejemplo n.º 4
0
bool RageSound::SetPositionFrames( int iFrames )
{
	LockMut( m_Mutex );

	if( m_pSource == NULL )
	{
		LOG->Warn( "RageSound::SetPositionFrames(%d): sound not loaded", iFrames );
		return false;
	}

	{
		/* "m_iDecodePosition" records the number of frames we've output to the
		 * speaker.  If the rate isn't 1.0, this will be different from the
		 * position in the sound data itself.  For example, if we're playing
		 * at 0.5x, and we're seeking to the 10th frame, we would have actually
		 * played 20 frames, and it's the number of real speaker frames that
		 * "m_iDecodePosition" represents. */
	    const int iScaledFrames = int( iFrames / GetPlaybackRate() );

	    /* If we're already there, don't do anything. */
	    if( m_iDecodePosition == iScaledFrames )
		    return true;

	    m_iStoppedPosition = m_iDecodePosition = iScaledFrames;
	}

	/* The position we're going to seek the input stream to.  We have
	 * to do this in floating point to avoid overflow. */
	int ms = int( float(iFrames) * 1000.f / samplerate() );
	ms = max(ms, 0);

	m_DataBuffer.clear();

	int ret;
	if( m_Param.AccurateSync )
		ret = m_pSource->SetPosition_Accurate(ms);
	else
		ret = m_pSource->SetPosition_Fast(ms);

	if(ret == -1)
	{
		/* XXX untested */
		Fail( m_pSource->GetError() );
		return false; /* failed */
	}

	if(ret == 0 && ms != 0)
	{
		/* We were told to seek somewhere, and we got 0 instead, which means
		 * we passed EOF.  This could be a truncated file or invalid data. */
		LOG->Warn("SetPositionFrames: %i ms is beyond EOF in %s",
			ms, GetLoadedFilePath().c_str());

		return false; /* failed */
	}

	return true;
}
Ejemplo n.º 5
0
bool RageSound::SetPositionSeconds( float fSeconds )
{
	if( m_pSource == NULL )
	{
		LOG->Warn( "RageSound::SetPositionSeconds(%f): sound not loaded", fSeconds );
		return false;
	}

	return SetPositionFrames( int(fSeconds * samplerate()) );
}
Ejemplo n.º 6
0
TranscodeProcess *DlnaYouTubeVideo::getTranscodeProcess()
{
    FfmpegTranscoding* transcodeProcess = new FfmpegTranscoding(log());

    transcodeProcess->setUrl(m_streamUrl);
    transcodeProcess->setLengthInSeconds(getLengthInSeconds());
    transcodeProcess->setFormat(transcodeFormat);
    transcodeProcess->setBitrate(bitrate());
    transcodeProcess->setAudioLanguages(audioLanguages());
    transcodeProcess->setSubtitleLanguages(subtitleLanguages());
    transcodeProcess->setFrameRate(framerate());
    transcodeProcess->setAudioChannelCount(channelCount());
    transcodeProcess->setAudioSampleRate(samplerate());
    return transcodeProcess;
}
Ejemplo n.º 7
0
float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const
{
	LockMut( m_Mutex );

	if( pTimestamp )
	{
		HOOKS->EnterTimeCriticalSection();
		pTimestamp->Touch();
	}

	const float fPosition = GetPositionSecondsInternal( bApproximate ) / float(samplerate());

	if( pTimestamp )
		HOOKS->ExitTimeCriticalSection();

	return GetPlaybackRate() * fPosition;
}
Ejemplo n.º 8
0
int main(int argc, char* argv[]) {
    size_t num_voices;
    char **fn_voices;
    char* in_fname;
    char* output_fname;
    FILE * outfp;
    char* dur_fname;
    FILE * durfp;    
    bool print_label = false;
    bool print_utt = false;
    bool write_raw = false;
    bool write_durlabel = false;

    CFSAString LexFileName, LexDFileName;
    HTS_Engine engine;
    double speed = 1.1;
    size_t fr = 48000;
    size_t fp = 240;
    float alpha = 0.55;
    float beta = 0.0;
    float ht = 2.0;
    float th = 0.5;
    float gvw1 = 1.0;
    float gvw2 = 1.2;

    FSCInit();
    fn_voices = (char **) malloc(argc * sizeof (char *));
    
    if (argc < 11) {
        fprintf(stderr, "Viga: liiga vähe parameetreid\n\n");
        PrintUsage();
    }    

    for (int i = 0; i < argc; i++) {
        if (CFSAString("-lex") == argv[i]) {
            if (i + 1 < argc) {
                LexFileName = argv[++i];
            } else {
                return PrintUsage();
            }
        }
        if (CFSAString("-lexd") == argv[i]) {
            if (i + 1 < argc) {
                LexDFileName = argv[++i];
            } else {
                return PrintUsage();
            }
        }
        if (CFSAString("-m") == argv[i]) {
            if (i + 1 < argc) {
                fn_voices[0] = argv[i + 1];
            } else {
                fprintf(stderr, "Viga: puudub *.htsvoice fail\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-o") == argv[i]) {
            if (i + 1 < argc) {
                output_fname = argv[i + 1];
                cfileexists(output_fname);
            } else {
                fprintf(stderr, "Viga: puudb väljundfaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-f") == argv[i]) {
            if (i + 1 < argc) {
                in_fname = argv[i + 1];
            } else {
                fprintf(stderr, "Viga: puudb sisendfaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-s") == argv[i]) {
            if (i + 1 < argc) {
                samplerate(fr, fp, alpha, atoi(argv[i + 1]));
            }
        }
        if (CFSAString("-r") == argv[i]) {
            if (i + 1 < argc) {
                speed = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-ht") == argv[i]) {
            if (i + 1 < argc) {
                ht = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-gvw1") == argv[i]) {
            if (i + 1 < argc) {
                gvw1 = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-gvw2") == argv[i]) {
            if (i + 1 < argc) {
                gvw2 = atof(argv[i + 1]);
            }
        }        
        if (CFSAString("-debug") == argv[i]) {
            print_label = true;
        }
        if (CFSAString("-utt") == argv[i]) {
            print_utt = true;
        }        
        if (CFSAString("-raw") == argv[i]) {
            write_raw = true;
        }
        if (CFSAString("-dur") == argv[i]) {
            if (i + 1 < argc) {
                dur_fname = argv[i + 1];
                cfileexists(dur_fname);
                write_durlabel = true;                
            } else {
                fprintf(stderr, "Viga: puudb kestustefaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }

        
    }

    Linguistic.Open(LexFileName);
    Disambiguator.Open(LexDFileName);

    CFSWString text;
    ReadUTF8Text(text, in_fname);
    HTS_Engine_initialize(&engine);

    if (HTS_Engine_load(&engine, fn_voices, 1) != TRUE) {
        fprintf(stderr, "Viga: puudub *.htsvoice. %p\n", fn_voices[0]);
        free(fn_voices);
        HTS_Engine_clear(&engine);
        exit(1);
    }
    free(fn_voices);

    HTS_Engine_set_sampling_frequency(&engine, (size_t) fr);
    HTS_Engine_set_phoneme_alignment_flag(&engine, FALSE);
    HTS_Engine_set_fperiod(&engine, (size_t) fp);
    HTS_Engine_set_alpha(&engine, alpha);
    HTS_Engine_set_beta(&engine, beta);
    HTS_Engine_set_speed(&engine, speed);
    HTS_Engine_add_half_tone(&engine, ht);
    HTS_Engine_set_msd_threshold(&engine, 1, th);
    /*
    HTS_Engine_set_duration_interpolation_weight(&engine, 1, diw);
    HTS_Engine_set_parameter_interpolation_weight(&engine, 0, 0, piw1);
    HTS_Engine_set_parameter_interpolation_weight(&engine, 0, 1, piw2);
    HTS_Engine_set_gv_interpolation_weight(&engine, 0, 0, giw1);
    HTS_Engine_set_gv_interpolation_weight(&engine, 0, 1, giw2);
     */
    HTS_Engine_set_gv_weight(&engine, 0, gvw1);
    HTS_Engine_set_gv_weight(&engine, 1, gvw2);

    text = DealWithText(text);
    CFSArray<CFSWString> res = do_utterances(text);

    INTPTR data_size = 0;
    outfp = fopen(output_fname, "wb");
    if (write_durlabel) durfp = fopen(dur_fname, "w");
    if (!write_raw) HTS_Engine_write_header(&engine, outfp, 1);
    for (INTPTR i = 0; i < res.GetSize(); i++) {

        CFSArray<CFSWString> label = do_all(res[i], print_label, print_utt);

        std::vector<std::string> v;
        v = to_vector(label);

        std::vector<char*> vc;
        fill_char_vector(v, vc);

        size_t n_lines = vc.size();

        if (HTS_Engine_synthesize_from_strings(&engine, &vc[0], n_lines) != TRUE) {
            fprintf(stderr, "Viga: süntees ebaonnestus.\n");            
            HTS_Engine_clear(&engine);
            exit(1);
        }

        clean_char_vector(vc);
        data_size += HTS_Engine_engine_speech_size(&engine);
        if (write_durlabel) HTS_Engine_save_durlabel(&engine, durfp);
        HTS_Engine_save_generated_speech(&engine, outfp);

        HTS_Engine_refresh(&engine);

    } //synth loop
    
    if (!write_raw) HTS_Engine_write_header(&engine, outfp, data_size);
    if (write_durlabel) fclose(durfp);
    fclose(outfp);

    HTS_Engine_clear(&engine);
    Linguistic.Close();

    FSCTerminate();
    return 0;

}
Ejemplo n.º 9
0
/* Retrieve audio data, for mixing.  At the time of this call, the frameno at which the
 * sound will be played doesn't have to be known.  Once committed, and the frameno
 * is known, call CommitPCMData.  size is in bytes.
 *
 * If the data returned is at the end of the stream, return false.
 *
 * size is in frames
 * iSoundFrame is in frames (abstract)
 */
bool RageSound::GetDataToPlay( int16_t *pBuffer, int iSize, int &iSoundFrame, int &iFramesStored )
{
	int iNumRewindsThisCall = 0;

	/* We only update m_iDecodePosition; only take a shared lock, so we don't block the main thread. */
//	LockMut(m_Mutex);

	ASSERT_M( m_bPlaying, ssprintf("%p", this) );

	iFramesStored = 0;
	iSoundFrame = m_iDecodePosition;

	while( 1 )
	{
		/* If we don't have any data left buffered, fill the buffer by
		 * up to as much as we need. */
		if( !Bytes_Available() )
			FillBuf( iSize );

		/* Get a block of data. */
		int iGotFrames = GetData( (char *) pBuffer, iSize );

		/* If we didn't get any data, see if we need to pad the end of the file with
		 * silence for m_LengthSeconds. */
		if( !iGotFrames && m_Param.m_LengthSeconds != -1 )
		{
			const float LastSecond = m_Param.m_StartSecond + m_Param.m_LengthSeconds;
			int LastFrame = int(LastSecond*samplerate());
			int FramesOfSilence = LastFrame - m_iDecodePosition;
			FramesOfSilence = clamp( FramesOfSilence, 0, iSize );
			if( FramesOfSilence > 0 )
			{
				memset( pBuffer, 0, FramesOfSilence * framesize );
				iGotFrames = FramesOfSilence;
			}
		}

		if( !iGotFrames )
		{
			/* EOF. */
			switch( GetStopMode() )
			{
			case RageSoundParams::M_STOP:
				/* Not looping.  Normally, we'll just stop here. */
				return false;

			case RageSoundParams::M_LOOP:
				/* Rewind and restart. */
				iNumRewindsThisCall++;
				if( iNumRewindsThisCall > 3 )
				{
					/* We're rewinding a bunch of times in one call.  This probably means
					 * that the length is too short.  It might also mean that the start
					 * position is very close to the end of the file, so we're looping
					 * over the remainder.  If we keep doing this, we'll chew CPU rewinding,
					 * so stop. */
					LOG->Warn( "Sound %s is busy looping.  Sound stopped (start = %f, length = %f)",
						GetLoadedFilePath().c_str(), m_Param.m_StartSecond, m_Param.m_LengthSeconds );

					return false;
				}

				/* Rewind and start over.  XXX: this will take an exclusive lock */
				SetPositionSeconds( m_Param.m_StartSecond );

				/* Make sure we can get some data.  If we can't, then we'll have
				 * nothing to send and we'll just end up coming back here. */
				if( !Bytes_Available() )
					FillBuf( iSize );
				if( GetData(NULL, iSize) == 0 )
				{
					LOG->Warn( "Can't loop data in %s; no data available at start point %f",
						GetLoadedFilePath().c_str(), m_Param.m_StartSecond );

					/* Stop here. */
					return false;
				}
				continue;

			case RageSoundParams::M_CONTINUE:
				/* Keep playing silence. */
				memset( pBuffer, 0, iSize*framesize );
				iGotFrames = iSize;
				break;

			default:
				ASSERT(0);
			}
		}

		/* This block goes from m_iDecodePosition to m_iDecodePosition+iGotFrames. */

		/* We want to fade when there's m_FadeLength seconds left, but if
		 * m_LengthFrames is -1, we don't know the length we're playing.
		 * (m_LengthFrames is the length to play, not the length of the
		 * source.)  If we don't know the length, don't fade. */
		if( m_Param.m_FadeLength != 0 && m_Param.m_LengthSeconds != -1 )
		{
			const float fFinishFadingOutAt = m_Param.m_StartSecond + m_Param.m_LengthSeconds;
			const float fStartFadingOutAt = fFinishFadingOutAt - m_Param.m_FadeLength;
			const float fStartSecond = float(m_iDecodePosition) / samplerate();
			const float fEndSecond = float(m_iDecodePosition+iGotFrames) / samplerate();
			const float fStartVolume = SCALE( fStartSecond, fStartFadingOutAt, fFinishFadingOutAt, 1.0f, 0.0f );
			const float fEndVolume = SCALE( fEndSecond, fStartFadingOutAt, fFinishFadingOutAt, 1.0f, 0.0f );
			RageSoundUtil::Fade( pBuffer, iGotFrames, fStartVolume, fEndVolume );
		}

		RageSoundUtil::Pan( pBuffer, iGotFrames, m_Param.m_Balance );

		iSoundFrame = m_iDecodePosition;

		iFramesStored = iGotFrames;
		m_iDecodePosition += iGotFrames;
		return true;
	}
}
Ejemplo n.º 10
0
/*
* Returns XML (DIDL) representation of the DLNA node. It gives a
* complete representation of the item, with as many tags as available.
*
* Reference: http://www.upnp.org/specs/av/UPnP-av-ContentDirectory-v1-Service.pdf
*/
QDomElement DlnaVideoItem::getXmlContentDirectory(QDomDocument *xml, QStringList properties) const {
    if (!xml)
        return QDomElement();

    QDomElement xml_obj = xml->createElement("item");

    updateXmlContentDirectory(xml, &xml_obj, properties);

    // properties optional of videoItem

    if (properties.contains("*") or properties.contains("upnp:genre")) {
        QDomElement upnpGenre = xml->createElement("upnp:genre");
        upnpGenre.appendChild(xml->createTextNode(metaDataGenre()));
        xml_obj.appendChild(upnpGenre);
    }

    if (properties.contains("*") or properties.contains("upnp:longDescription")) {

    }

    if (properties.contains("*") or properties.contains("upnp:producer")) {

    }

    if (properties.contains("*") or properties.contains("upnp:rating")) {

    }

    if (properties.contains("*") or properties.contains("upnp:actor")) {

    }

    if (properties.contains("*") or properties.contains("upnp:director")) {

    }

    if (properties.contains("*") or properties.contains("dc:description")) {

    }

    if (properties.contains("*") or properties.contains("dc:publisher")) {

    }

    if (properties.contains("*") or properties.contains("dc:language")) {

    }

    if (properties.contains("*") or properties.contains("dc:relation")) {

    }

    // add <res> element

    QTime duration(0, 0, 0);
    QDomElement res = xml->createElement("res");
    res.setAttribute("xmlns:dlna", "urn:schemas-dlna-org:metadata-1-0/");

    // mandatory properties: protocolInfo
    res.setAttribute("protocolInfo", getProtocolInfo());

    // optional properties
    if ((properties.contains("*") or properties.contains("res@bitrate")) and bitrate() != -1) {
        // bitrate in bytes/sec
        res.setAttribute("bitrate", QString("%1").arg(qRound(double(bitrate())/8.0)));
    }

    if (properties.contains("*") or properties.contains("res@resolution")) {
        res.setAttribute("resolution", resolution());
    }

    if (properties.contains("*") or properties.contains("res@duration")) {
        res.setAttribute("duration", QString("%1").arg(duration.addSecs(getLengthInSeconds()).toString("hh:mm:ss")));
    }

    if (properties.contains("*") or properties.contains("res@sampleFrequency")) {
        res.setAttribute("sampleFrequency", QString("%1").arg(samplerate()));
    }

    if (properties.contains("*") or properties.contains("res@nrAudioChannels")) {
        res.setAttribute("nrAudioChannels", QString("%1").arg(channelCount()));
    }

    if ((properties.contains("*") or properties.contains("res@size")) and size() != -1) {
        // size in bytes
        res.setAttribute("size", QString("%1").arg(size()));
    }

    res.appendChild(xml->createTextNode(QString("http://%2:%3/get/%1/%4").arg(getResourceId()).arg(host).arg(port).arg(getName().toUtf8().toPercentEncoding().constData())));

    xml_obj.appendChild(res);

    return xml_obj;
}