Exemplo n.º 1
0
SmpLength InsertSilence(modplug::tracker::modsample_t& smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, module_renderer* pSndFile)
//-----------------------------------------------------------------------------------------------------------------------
{
    if(nSilenceLength == 0 || nSilenceLength >= MAX_SAMPLE_LENGTH || smp.length > MAX_SAMPLE_LENGTH - nSilenceLength)
            return smp.length;

    const SmpLength nOldBytes = smp.GetSampleSizeInBytes();
    const SmpLength nSilenceBytes = nSilenceLength * smp.GetBytesPerSample();
    const SmpLength nNewSmpBytes = nOldBytes + nSilenceBytes;
    const SmpLength nNewLength = smp.length + nSilenceLength;

    LPSTR pNewSmp = 0;
    if( GetSampleCapacity(smp) >= nNewSmpBytes ) // If sample has room to expand.
    {
            AfxMessageBox("Not implemented: GetSampleCapacity(smp) >= nNewSmpBytes");
            // Not implemented, GetSampleCapacity() currently always returns length based value
            // even if there is unused space in the sample.
    }
    else // Have to allocate new sample.
    {
            pNewSmp = module_renderer::AllocateSample(nNewSmpBytes);
            if(pNewSmp == 0)
                    return smp.length; //Sample allocation failed.
            if(nStartFrom == 0)
            {
                    memset(pNewSmp, 0, nSilenceBytes);
                    memcpy(pNewSmp + nSilenceBytes, smp.sample_data, nOldBytes);
            }
            else if(nStartFrom == smp.length)
            {
                    memcpy(pNewSmp, smp.sample_data, nOldBytes);
                    memset(pNewSmp + nOldBytes, 0, nSilenceBytes);
            }
            else
                    AfxMessageBox(TEXT("Unsupported start position in InsertSilence."));
    }

    // Set loop points automatically
    if(nOldBytes == 0)
    {
            smp.loop_start = 0;
            smp.loop_end = nNewLength;
            smp.flags |= CHN_LOOP;
    } else
    {
            if(smp.loop_start >= nStartFrom) smp.loop_start += nSilenceLength;
            if(smp.loop_end >= nStartFrom) smp.loop_end += nSilenceLength;
    }

    ReplaceSample(smp, pNewSmp, nNewLength, pSndFile);
    AdjustEndOfSample(smp, pSndFile);

    return smp.length;
}
Exemplo n.º 2
0
SmpLength InsertSilence(ModSample &smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, CSoundFile &sndFile)
//----------------------------------------------------------------------------------------------------------------------
{
	if(nSilenceLength == 0 || nSilenceLength > MAX_SAMPLE_LENGTH || smp.nLength > MAX_SAMPLE_LENGTH - nSilenceLength || nStartFrom > smp.nLength)
		return smp.nLength;

	const bool wasEmpty = smp.nLength == 0 || smp.pSample == nullptr;
	const SmpLength newLength = smp.nLength + nSilenceLength;

	char *pNewSmp = nullptr;

	pNewSmp = static_cast<char *>(ModSample::AllocateSample(newLength, smp.GetBytesPerSample()));
	if(pNewSmp == nullptr)
		return smp.nLength; //Sample allocation failed.

	if(!wasEmpty)
	{
		// Copy over old sample
		const SmpLength silenceOffset = nStartFrom * smp.GetBytesPerSample();
		const SmpLength silenceBytes = nSilenceLength * smp.GetBytesPerSample();
		if(nStartFrom > 0)
		{
			memcpy(pNewSmp, smp.pSample, silenceOffset);
		}
		if(nStartFrom < smp.nLength)
		{
			memcpy(pNewSmp + silenceOffset + silenceBytes, static_cast<const char *>(smp.pSample) + silenceOffset, smp.GetSampleSizeInBytes() - silenceOffset);
		}

		// Update loop points if necessary.
		if(smp.nLoopStart >= nStartFrom) smp.nLoopStart += nSilenceLength;
		if(smp.nLoopEnd >= nStartFrom) smp.nLoopEnd += nSilenceLength;
	} else
	{
		// Set loop points automatically
		smp.nLoopStart = 0;
		smp.nLoopEnd = newLength;
		smp.uFlags.set(CHN_LOOP);
	}

	ReplaceSample(smp, pNewSmp, newLength, sndFile);
	PrecomputeLoops(smp, sndFile, true);

	return smp.nLength;
}
Exemplo n.º 3
0
SmpLength ResizeSample(modplug::tracker::modsample_t& smp, const SmpLength nNewLength, module_renderer* pSndFile)
//--------------------------------------------------------------------------------------
{
    // Invalid sample size
    if(nNewLength > MAX_SAMPLE_LENGTH || nNewLength == smp.length)
            return smp.length;

    // New sample will be bigger so we'll just use "InsertSilence" as it's already there.
    if(nNewLength > smp.length)
            return InsertSilence(smp, nNewLength - smp.length, smp.length, pSndFile);

    // Else: Shrink sample

    const SmpLength nNewSmpBytes = nNewLength * smp.GetBytesPerSample();

    LPSTR pNewSmp = 0;
    pNewSmp = module_renderer::AllocateSample(nNewSmpBytes);
    if(pNewSmp == 0)
            return smp.length; //Sample allocation failed.

    // Copy over old data and replace sample by the new one
    memcpy(pNewSmp, smp.sample_data, nNewSmpBytes);
    ReplaceSample(smp, pNewSmp, nNewLength, pSndFile);

    // Adjust loops
    if(smp.loop_start > nNewLength)
    {
            smp.loop_start = smp.loop_end = 0;
            smp.flags &= ~CHN_LOOP;
    }
    if(smp.loop_end > nNewLength) smp.loop_end = nNewLength;
    if(smp.sustain_start > nNewLength)
    {
            smp.sustain_start = smp.sustain_end = 0;
            smp.flags &= ~CHN_SUSTAINLOOP;
    }
    if(smp.sustain_end > nNewLength) smp.sustain_end = nNewLength;

    AdjustEndOfSample(smp, pSndFile);

    return smp.length;
}
Exemplo n.º 4
0
SmpLength ResizeSample(ModSample &smp, const SmpLength nNewLength, CSoundFile &sndFile)
//-------------------------------------------------------------------------------------
{
	// Invalid sample size
	if(nNewLength > MAX_SAMPLE_LENGTH || nNewLength == smp.nLength)
		return smp.nLength;

	// New sample will be bigger so we'll just use "InsertSilence" as it's already there.
	if(nNewLength > smp.nLength)
		return InsertSilence(smp, nNewLength - smp.nLength, smp.nLength, sndFile);

	// Else: Shrink sample

	const SmpLength nNewSmpBytes = nNewLength * smp.GetBytesPerSample();

	void *pNewSmp = ModSample::AllocateSample(nNewLength, smp.GetBytesPerSample());
	if(pNewSmp == nullptr)
		return smp.nLength; //Sample allocation failed.

	// Copy over old data and replace sample by the new one
	memcpy(pNewSmp, smp.pSample, nNewSmpBytes);
	ReplaceSample(smp, pNewSmp, nNewLength, sndFile);

	// Adjust loops
	if(smp.nLoopStart > nNewLength)
	{
		smp.nLoopStart = smp.nLoopEnd = 0;
		smp.uFlags.reset(CHN_LOOP);
	}
	if(smp.nLoopEnd > nNewLength) smp.nLoopEnd = nNewLength;
	if(smp.nSustainStart > nNewLength)
	{
		smp.nSustainStart = smp.nSustainEnd = 0;
		smp.uFlags.reset(CHN_SUSTAINLOOP);
	}
	if(smp.nSustainEnd > nNewLength) smp.nSustainEnd = nNewLength;

	PrecomputeLoops(smp, sndFile);

	return smp.nLength;
}