1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
//#include "stdafx.h"
#include "TZXBlockTurboSpeedData.h"
#include "TZXFile.h"
#include <stdlib.h>
#include <stdio.h>
TZXBlockTurboSpeedData::TZXBlockTurboSpeedData()
{
m_nBlockID = TZX_BLOCKID_TURBO_SPEED_DATA;
m_pData = NULL;
}
TZXBlockTurboSpeedData::~TZXBlockTurboSpeedData()
{
if (m_pData) free(m_pData);
}
char *TZXBlockTurboSpeedData::GetDescription()
{
snprintf((char *)m_szToStringDescription, MAX_STRING_LENGTH, "Turbo Speed Data Block: %d bytes. Delay = %d ms", m_nDataLength, m_nDelayAfterBlock);
return m_szToStringDescription;
}
void TZXBlockTurboSpeedData::GenerateAudio(TZXAudioGenerator *pAudioGenerator, TZXFile *pTZXFile)
{
//printf("Block starts at time %0.3f\n", (float)(pAudioGenerator->GetCurrentLength()) / 44100.0f);
// Store the offset location for the current block
m_nAudioBufferOffsetLocation = pAudioGenerator->GetCurrentLength();
pAudioGenerator->SetAmp(false); // Make sure the pilot always starts on a false.
for (int i = 0; i <= m_nPilotCount; i++)
{
pAudioGenerator->GeneratePulse(m_nPilotPulse);
}
// Generate the two sync pulses
pAudioGenerator->GeneratePulse(m_nFirstSyncPulse);
pAudioGenerator->GeneratePulse(m_nSecondSyncPulse);
// Generate the actual data
for (int i = 0; i < m_nDataLength; i++)
{
int bits = 8;
if (i == (m_nDataLength - 1)) bits = m_nBitsInLastByte;
for (int n = 0; n<bits; n++)
{
char mask = 1 << (7-n);
char bitset = m_pData[i] & mask;
if (bitset)
{
// Write a one bit
pAudioGenerator->GeneratePulse(m_nOneBitPulse);
pAudioGenerator->GeneratePulse(m_nOneBitPulse);
}
else {
// Write a zero bit
pAudioGenerator->GeneratePulse(m_nZeroBitPulse);
pAudioGenerator->GeneratePulse(m_nZeroBitPulse);
}
}
}
// Add any delay at the end of the block
if (m_nDelayAfterBlock) pAudioGenerator->AddSilence(m_nDelayAfterBlock);
}
|