2016-12-11 5 views
0

LTSpice의 파일 입력 기능을 사용하여 실제 오디오 비트를 사용하는 회로를 시뮬레이트하고 싶습니다. 나는 시간 대 진폭 버전의 데이터가 필요하지만 어느 소프트웨어 패키지가 나를 위해 이것을 할 수 있는지 확실하지 않다. Audacity는 MP3를 WAV로 변환 할 수는 있지만 헤더없는 텍스트 파일에서는 볼 수 없습니다.WAV를 시간과 진폭의 txt 파일로 변경하려면 어떻게해야합니까?

그래서 .WAV 파일은 시간/진폭의 2 열 텍스트 파일에 있습니다.

자유로운 방법에 대한 아이디어가 있습니까?

+0

이 작업을 수행 할 수있는 소프트웨어를 사용하고 계시겠습니까? 질문을 편집하여 입력 샘플과 예상 출력을 제공하면 답변을 받게됩니다. – enhzflep

답변

0

다음은 javascript를 사용한 빠른 구현입니다.

결과 문자열을 쉽게 다운로드 할 수있는 BLOB로 변환하는 연습으로 남겨 두겠다. 채널 선택, 스테레오 결과 및 처리를 위해 오디오 트랙의 작은 부분을 선택할 수있는 기능을 남겨 두겠다.

<!doctype html> 
<html> 
<head> 
<script> 
"use strict"; 
function byId(id){return document.getElementById(id)} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
window.addEventListener('load', onDocLoaded, false); 

var audioCtx; 

function onDocLoaded(evt) 
{ 
    audioCtx = new AudioContext(); 
    byId('fileInput').addEventListener('change', onFileInputChangedGeneric, false); 
} 

function onFileInputChangedGeneric(evt) 
{ 
    // load file if chosen 
    if (this.files.length != 0) 
    { 
     var fileObj = this.files[0]; 
     loadAndTabulateAudioFile(fileObj, byId('output')); 
    } 
    // clear output otherwise 
    else 
     byId('output').textContent = ''; 
} 

// processes channel 0 only 
// 
// creates a string that represents a 2 column table, where each row contains the time and amplitude of a sample 
// columns are tab seperated 
function loadAndTabulateAudioFile(fileObj, tgtElement) 
{ 
    var a = new FileReader(); 
    a.onload = loadedCallback; 
    a.readAsArrayBuffer(fileObj); 
    function loadedCallback(evt) 
    { 
     audioCtx.decodeAudioData(evt.target.result, onDataDecoded); 
    } 
    function onDataDecoded(buffer) 
    { 
     //console.log(buffer); 
     var leftChannel = buffer.getChannelData(0); 

     //var rightChannel = buffer.getChannelData(1); 
     console.log("# samples: " + buffer.length); 
     console.log(buffer); 

     var result = ''; 
     var i, n = buffer.length, invSampleRate = 1.0/buffer.sampleRate; 
     for (i=0; i<n; i++) 
     { 
      var curResult = (invSampleRate*i).toFixed(8) + "\t" + leftChannel[i] + "\n"; 
      result += curResult; 
     } 
     tgtElement.textContent = result; 
    } 
} 

</script> 
<style> 
</style> 
</head> 
<body> 
    <label>Select audio file: <input type='file' id='fileInput'/></label> 
    <hr> 
    <pre id='output'></pre> 
</body> 
</html>