Guest User

Untitled

a guest
Jun 21st, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.82 KB | None | 0 0
  1. import streams as s
  2.  
  3. const
  4.   WAVFILE_SAMPLES_PER_SECOND = 44_100
  5.   BITS_PER_SAMPLE = 16
  6.   NUMBER_OF_CHANNELS = 1  # 1 for mono, 2 for stero
  7.  
  8. type
  9.   WAV = object
  10.     rtag: string
  11.     rlen: int
  12.     wtag: string
  13.     ftag: string
  14.     flen: int
  15.     afmt: int16
  16.     nchl: int16
  17.     srte: int
  18.     brte: int
  19.     baln: int16
  20.     bsps: int16
  21.     dtag: string
  22.     dlen: int
  23.  
  24. var
  25.   wav: WAV
  26.  
  27. wav.rtag = "RIFF"
  28. wav.rlen = 0
  29. wav.wtag = "WAVE"
  30. wav.ftag = "fmt "
  31. wav.flen = 16
  32. wav.afmt = 1
  33. wav.nchl = NUMBER_OF_CHANNELS
  34. wav.srte = WAVFILE_SAMPLES_PER_SECOND
  35. wav.brte = WAVFILE_SAMPLES_PER_SECOND*int(BITS_PER_SAMPLE/8)
  36. wav.baln = int16(BITS_PER_SAMPLE/8)
  37. wav.bsps = BITS_PER_SAMPLE
  38. wav.dtag = "data"
  39. wav.dlen = 0
  40.  
  41. var fs = s.newFileStream("test.wav", fmWrite)
  42. if not isNil(fs):
  43.   fs.write(wav)
  44.   fs.close()
Advertisement
Add Comment
Please, Sign In to add comment