最近モールス信号にはまって、HSP でモールス符号を鳴らせるようにスクリプトを作ったのですが
なぜか急に途中で落ちてしまいます。
>スクリプト↓
*Init #ifndef _WAVEOUT_H_ #define _WAVEOUT_H_ #include "winmm.as" #module _WAVEOUT_M_ // // モジュール初期化 // #deffunc local init // WAVEFORMATEX 構造体 wBytesPerSample = 2 // 量子化バイト数 wFormatTag = 0x0001 // WAVE_FORMAT_PCM nChannels = 2 // ステレオ nSamplesPerSec = 44100 // サンプルレート wBitsPerSample = wBytesPerSample * 8 nBlockAlign = nChannels * wBytesPerSample nAvgBytesPerSec = nSamplesPerSec * nBlockAlign cbSize = 0 wfex = wFormatTag | (nChannels << 16), nSamplesPerSec, nAvgBytesPerSec, nBlockAlign | (wBitsPerSample << 16), cbSize // オープン hWaveOut = 0 waveOutOpen varptr(hWaveOut), -1, varptr(wfex), 0, 0, 0 // WAVE_MAPPER, CALLBACK_NULL return // // モジュール終了処理 // #deffunc exit onexit // クローズ waveOutReset hWaveOut waveOutUnprepareHeader hWaveOut, varptr(whdr), 32 // sizeof(WAVEHDR) waveOutClose hWaveOut return // // wave 出力 // // _wave : 波形データの入った変数 // _nAvgBytes : 波形データのバイト数 // #deffunc waveOut var _wave, int _nAvgBytes // WAVEHDR 構造体 lpData = varptr(_wave) dwBufferLength = _nAvgBytes dwBytesRecorded = 0 dwUser = 0 dwFlags = 12 // WHDR_BEGINLOOP | WHDR_ENDLOOP dwLoops = 1 // ループ回数 lpNext = 0 reserved = 0 whdr = lpData, dwBufferLength, dwBytesRecorded, dwUser, dwFlags, dwLoops, lpNext, reserved // 再生 waveOutReset hWaveOut waveOutPrepareHeader hWaveOut, varptr(whdr), 32 // sizeof(WAVEHDR) waveOutWrite hWaveOut, varptr(whdr), 32 // sizeof(WAVEHDR) return // // サイン波出力 // // f : 周波数 (ヘルツ単位) // a : 振幅 (0.0 〜 1.0) // t : 時間 (秒単位) // #deffunc waveOutSine double f, double a, double t // 波形データ nSamples = int(t * nSamplesPerSec) // 全体のサンプル数 nAvgBytes = nSamples * nBlockAlign // 全体のバイト数 dim wave, (nAvgBytes + 3) / 4 repeat nSamples // この部分は nChannels や wBytesPerSample によって書き換えが必要 wpoke wave, cnt * 4 , int(sin(2.0 * M_PI * f * cnt / nSamplesPerSec) * 0x7FFF * a) & 0xFFFF wpoke wave, cnt * 4 + 2, int(sin(2.0 * M_PI * f * cnt / nSamplesPerSec) * 0x7FFF * a) & 0xFFFF loop // 再生 waveOut wave, nAvgBytes return #global init@_WAVEOUT_M_ #endif screen 0, 640, 480 goto *Main_ObjAndOther *Main_ObjAndOther Quantize = 7 short = 1 long = 3 spaceshort = 3 spacelong = 7 文章 = "SSSSLSLSSSLSSLLL LSSSLSLLS" 文章コピー = 文章 mes 文章 count = -1 goto *Main *Main count ++ PlayNow = peek(文章コピー, count) if PlayNow = 0 : stop mes "文字コード --> " + PlayNow + " " if PlayNow = 83 { waveOutSine 440.0, 0.25, Quantize * short ; S wait (Quantize * short) + (Quantize * spaceshort) / 10 } if PlayNow = 76 { waveOutSine 440.0, 0.25, Quantize * long ; L wait (Quantize * long) + (Quantize * spaceshort) / 10 } if PlayNow = 32 { wait Quantize * spacelong / 10 ; SPACE LONG } goto *Main
仕組みは「文章コピー」を peek で一文字ずつ取得して、「S」だったら短い音(Quantize * short)
「L」だったら長い音(Quantize * long)で半角スペースだったら Quantize * spacelong ウェイトする
というかんじです