Exemplo n.º 1
0
void QTapeView::openTape(const QString &sFileName)
{
    LPCTSTR lpszFile = qPrintable(sFileName);
    m_hTapeWavPcmFile = WavPcmFile_Open(lpszFile);
    if (m_hTapeWavPcmFile == INVALID_HANDLE_VALUE)
        return;  //TODO: Report about a bad WAV file

    m_sTapeFile = sFileName;
    m_okTapeInserted = true;
    m_okTapeRecording = false;

    m_buttonPlay->setEnabled(true);
    m_buttonPlay->setText(_T("Play"));
    m_buttonRewind->setEnabled(true);
    m_labelFile->setText(lpszFile);

    this->updatePosition();

    DWORD wavLength = WavPcmFile_GetLength((HWAVPCMFILE)m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency((HWAVPCMFILE)m_hTapeWavPcmFile);
    double wavLengthSeconds = double(wavLength) / wavFreq;

    TCHAR buffer[64];
    _sntprintf(buffer, 64, _T("%d:%02d.%02d, %d Hz"),
        int(wavLengthSeconds) / 60, int(wavLengthSeconds) % 60, int(wavLengthSeconds * 100) % 100, wavFreq);
    m_labelTotal->setText(buffer);

    m_buttonOpen->setText(_T("Close WAV"));
    m_buttonSave->setEnabled(false);
}
Exemplo n.º 2
0
bool QTapeView::tapeReadCallback(unsigned int samples)
{
    if (m_hTapeWavPcmFile == (HWAVPCMFILE)INVALID_HANDLE_VALUE) return 0;
    if (m_okTapeRecording) return 0;
    if (samples == 0) return 0;

    unsigned int value = 0;
    for (unsigned int i = 0; i < samples; i++)
    {
        value = WavPcmFile_ReadOne((HWAVPCMFILE)m_hTapeWavPcmFile);
    }
    BOOL result = (value > 0xffffffff / 2);

    DWORD wavLength = WavPcmFile_GetLength((HWAVPCMFILE)m_hTapeWavPcmFile);
    DWORD wavPos = WavPcmFile_GetPosition((HWAVPCMFILE)m_hTapeWavPcmFile);
    if (wavPos >= wavLength)  // End of tape
        this->stopTape();

    int wavFreq = WavPcmFile_GetFrequency((HWAVPCMFILE)m_hTapeWavPcmFile);
    if (wavPos - m_dwTapePositionShown > (DWORD)(wavFreq / 6) || !m_okTapePlaying)
    {
        this->updatePosition();
    }

    return result;
}
Exemplo n.º 3
0
void CALLBACK TapeView_TapeWriteCallback(int value, UINT samples)
{
    if (m_hTapeWavPcmFile == (HWAVPCMFILE)INVALID_HANDLE_VALUE) return;
    if (!m_okTapeRecording) return;
    if (samples == 0) return;

    // Scroll buffer
    memmove(m_TapeBuffer, m_TapeBuffer + samples, TAPE_BUFFER_SIZE - samples);

    // Write samples to the file
    for (UINT i = 0; i < samples; i++)
    {
        WavPcmFile_WriteOne(m_hTapeWavPcmFile, value);
        //TODO: Check WavPcmFile_WriteOne result
        *(m_TapeBuffer + TAPE_BUFFER_SIZE - samples + i) = (BYTE)((value >> 24) & 0xff);
    }

    InvalidateRect(m_hwndTapeGraph, NULL, FALSE);

    DWORD wavPos = WavPcmFile_GetPosition(m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency(m_hTapeWavPcmFile);
    if (wavPos - m_dwTapePositionShown > (DWORD)(wavFreq / 6) || !m_okTapePlaying)
    {
        TapeView_UpdatePosition();
    }
}
Exemplo n.º 4
0
// Tape emulator callback used to read a tape recorded data.
// Input:
//   samples    Number of samples to play.
// Output:
//   result     Bit to put in tape input port.
BOOL CALLBACK TapeView_TapeReadCallback(unsigned int samples)
{
    if (samples == 0) return 0;

    // Scroll buffer
    memmove(m_TapeBuffer, m_TapeBuffer + samples, TAPE_BUFFER_SIZE - samples);

    UINT value = 0;
    for (UINT i = 0; i < samples; i++)
    {
        value = WavPcmFile_ReadOne(m_hTapeWavPcmFile);
        *(m_TapeBuffer + TAPE_BUFFER_SIZE - samples + i) = (BYTE)((value >> 24) & 0xff);
    }
    BOOL result = (value >= UINT_MAX / 2);

    InvalidateRect(m_hwndTapeGraph, NULL, FALSE);

    DWORD wavLength = WavPcmFile_GetLength(m_hTapeWavPcmFile);
    DWORD wavPos = WavPcmFile_GetPosition(m_hTapeWavPcmFile);
    if (wavPos >= wavLength)  // End of tape
        TapeView_StopTape();

    int wavFreq = WavPcmFile_GetFrequency(m_hTapeWavPcmFile);
    if (wavPos - m_dwTapePositionShown > (DWORD)(wavFreq / 6) || !m_okTapePlaying)
    {
        TapeView_UpdatePosition();
    }

//#if !defined(PRODUCT)
//    DebugPrintFormat(_T("Tape: %d\r\n"), result);
//#endif

    return result;
}
Exemplo n.º 5
0
void TapeView_OpenTape(LPCTSTR lpszFile)
{
    m_hTapeWavPcmFile = WavPcmFile_Open(lpszFile);
    if (m_hTapeWavPcmFile == INVALID_HANDLE_VALUE)
        return;  //TODO: Report about a bad WAV file

    _tcscpy_s(m_szTapeFile, MAX_PATH, lpszFile);
    m_okTapeInserted = TRUE;
    m_okTapeRecording = FALSE;

    EnableWindow(m_hwndTapePlay, TRUE);
    SetWindowText(m_hwndTapePlay, _T("Play"));
    EnableWindow(m_hwndTapeRewind, TRUE);
    SetWindowText(m_hwndTapeFile, lpszFile);

    TapeView_UpdatePosition();
    TapeView_ClearGraph();

    DWORD wavLength = WavPcmFile_GetLength(m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency(m_hTapeWavPcmFile);
    double wavLengthSeconds = double(wavLength) / wavFreq;

    TCHAR buffer[64];
    wsprintf(buffer, _T("%d:%02d.%02d, %d Hz"),
            int(wavLengthSeconds) / 60, int(wavLengthSeconds) % 60, int(wavLengthSeconds * 100) % 100, wavFreq);
    SetWindowText(m_hwndTapeTotal, buffer);

    SetWindowText(m_hwndTapeOpen, _T("Close WAV"));
    EnableWindow(m_hwndTapeSave, FALSE);
}
Exemplo n.º 6
0
void QTapeView::updatePosition()
{
    DWORD wavPos = WavPcmFile_GetPosition((HWAVPCMFILE)m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency((HWAVPCMFILE)m_hTapeWavPcmFile);
    double wavPosSeconds = double(wavPos) / wavFreq;
    TCHAR buffer[64];
    _sntprintf(buffer, 64, _T("%d:%02d.%02d"),
        int(wavPosSeconds) / 60, int(wavPosSeconds) % 60, int(wavPosSeconds * 100) % 100);
    m_labelCurrent->setText(buffer);

    m_dwTapePositionShown = wavPos;
}
Exemplo n.º 7
0
void TapeView_UpdatePosition()
{
    DWORD wavPos = WavPcmFile_GetPosition(m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency(m_hTapeWavPcmFile);
    double wavPosSeconds = double(wavPos) / wavFreq;
    TCHAR buffer[64];
    wsprintf(buffer, _T("%d:%02d.%02d"),
            int(wavPosSeconds) / 60, int(wavPosSeconds) % 60, int(wavPosSeconds * 100) % 100);
    SetWindowText(m_hwndTapeCurrent, buffer);

    m_dwTapePositionShown = wavPos;
}
Exemplo n.º 8
0
void TapeView_PlayTape()
{
    if (m_okTapePlaying) return;
    if (!m_okTapeInserted) return;

    int sampleRate = WavPcmFile_GetFrequency(m_hTapeWavPcmFile);

    if (m_okTapeRecording)
        g_pBoard->SetTapeWriteCallback(TapeView_TapeWriteCallback, sampleRate);
    else
        g_pBoard->SetTapeReadCallback(TapeView_TapeReadCallback, sampleRate);

    m_okTapePlaying = TRUE;
    SetWindowText(m_hwndTapePlay, _T("Stop"));
}
Exemplo n.º 9
0
void QTapeView::playTape()
{
    if (m_okTapePlaying) return;
    if (!m_okTapeInserted) return;

    int sampleRate = WavPcmFile_GetFrequency((HWAVPCMFILE)m_hTapeWavPcmFile);

    if (m_okTapeRecording)
        g_pBoard->SetTapeWriteCallback(TapeView_TapeWriteCallback, sampleRate);
    else
        g_pBoard->SetTapeReadCallback(TapeView_TapeReadCallback, sampleRate);

    m_okTapePlaying = true;

    m_buttonPlay->setText(_T("Stop"));
}
Exemplo n.º 10
0
void QTapeView::tapeWriteCallback(int value, unsigned int samples)
{
    if (m_hTapeWavPcmFile == (HWAVPCMFILE)INVALID_HANDLE_VALUE) return;
    if (!m_okTapeRecording) return;
    if (samples == 0) return;

    // Write samples to the file
    for (unsigned int i = 0; i < samples; i++)
        WavPcmFile_WriteOne((HWAVPCMFILE)m_hTapeWavPcmFile, value);

    DWORD wavPos = WavPcmFile_GetPosition((HWAVPCMFILE)m_hTapeWavPcmFile);
    int wavFreq = WavPcmFile_GetFrequency((HWAVPCMFILE)m_hTapeWavPcmFile);
    if (wavPos - m_dwTapePositionShown > (DWORD)(wavFreq / 6) || !m_okTapePlaying)
    {
        this->updatePosition();
    }
}