Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
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);
}
Exemple #4
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);
}