Author Topic: Compiler issue with sound commands  (Read 12502 times)

0 Members and 1 Guest are viewing this topic.

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Compiler issue with sound commands
« Reply #45 on: October 09, 2018, 11:38:26 pm »
Specs? All I know is what Windows tells me, by right-clicking.

Size = 4.45 MB (4,671,738 bytes)

Length = 13 seconds

Bit rate = 2.822 Mb/s

By the looks of it, should be great quality sound!

FellippeHeitor

  • Guest
Re: Compiler issue with sound commands
« Reply #46 on: October 09, 2018, 11:49:43 pm »
Indeed.

Converted to .ogg it plays just fine (not to mention it's a fraction of the size). Here:  [ You are not allowed to view this attachment ]  

Something in OpenAL isn't happy about the encoding in your original wave file.

OpenAL also brings some restrictions to the way programs compiled with QB64 using audio should be distributed (source should be published).

If a new cross-platform open source sound library shows up, all these issues are likely to go away.

Bear with us.

Fellippe.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Compiler issue with sound commands
« Reply #47 on: October 10, 2018, 03:22:19 am »
Hello. Now I found this thread. I'm developing a big and sophisticated program, so here I am less. But to the point.
synth.wav is 32 bit recorded wav file. I've upgraded that simple version and it's already playing. It was not a 32-bit format (the old version does not have 32 bit wav, support, this one already support it). If i get a WAV mixed in 64 and 128 bits, then program can be done  for 100% tuning.

Code: QB64: [Select]
  1. wav "synth.wav"
  2.  
  3. SUB wav (file$)
  4.     TYPE head
  5.         chunk AS STRING * 4 '       4 bytes  (RIFF)
  6.         size AS LONG '              4 bytes  (?E??)
  7.         fomat AS STRING * 4 '       4 bytes  (WAVE)
  8.         sub1 AS STRING * 4 '        4 bytes  (fmt )
  9.         subchunksize AS LONG '      4 bytes  (lo / hi), $00000010 for PCM audio
  10.         format AS STRING * 2 '      2 bytes  (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM)
  11.         channels AS INTEGER '       2 bytes  (1 = mono, 2 = stereo)
  12.         rate AS LONG '              4 bytes  (sample rate, standard is 44100)
  13.         ByteRate AS LONG '          4 bytes  (= sample rate * number of channels * (bits per channel /8))
  14.         Block AS INTEGER '          2 bytes  (block align = number of channels * bits per sample /8)
  15.         Bits AS INTEGER '           2 bytes  (bits per sample. 8 = 8, 16 = 16)
  16.         subchunk2 AS STRING * 4 '   4 bytes  ("data")  contains begin audio samples
  17.     END TYPE '                     40 bytes  total
  18.     DIM H AS head
  19.     ch = FREEFILE
  20.  
  21.     IF _FILEEXISTS(file$) THEN OPEN file$ FOR BINARY AS #ch ELSE PRINT file$; " not found": SLEEP 2: SYSTEM
  22.     GET #ch, , H
  23.  
  24.     block = H.Block
  25.     RATE = H.rate
  26.     chan = H.channels
  27.     bits = H.Bits
  28.  
  29.     DO WHILE NOT EOF(ch)
  30.         '------------------------------------------ UPGRADE FOR SYNTH.WAV ------------------------------------------------------------------ IF STEREO
  31.         IF bits = 32 AND chan = 2 THEN
  32.             DO WHILE NOT EOF(ch)
  33.                 REDIM lefi32 AS SINGLE, righi32 AS SINGLE ' MAYBE! FOR 64 bit WAV here use DOUBLE TYPE. (NOT TESTED with 64 bit WAV)
  34.                 GET #ch, , lefi32
  35.                 GET #ch, , righi32
  36.                 _SNDRAW lefi32, righi32
  37.                 DO WHILE _SNDRAWLEN > 0: LOOP
  38.             LOOP
  39.             END
  40.         END IF
  41.         '------------------------------------------ UPGRADE FOR SYNTH.WAV ------------------------------------------------------------------ IF MONO
  42.         IF bits = 32 AND chan = 1 THEN
  43.             DO WHILE NOT EOF(ch)
  44.                 REDIM leftMono32 AS SINGLE
  45.                 GET #ch, , leftMono32
  46.                 _SNDRAW leftMono32, leftMono32
  47.                 DO WHILE _SNDRAWLEN > 0: LOOP
  48.             LOOP
  49.         END IF
  50.         '-------------------------------------------- CONTINUE AS OLD SOURCE ---------------------------------------------------------------
  51.  
  52.         IF bits = 16 AND chan = 2 THEN
  53.             REDIM lefi AS INTEGER, righi AS INTEGER
  54.             GET #ch, , lefi
  55.             GET #ch, , righi
  56.             lef = lefi / RATE
  57.             righ = righi / RATE
  58.         END IF
  59.  
  60.         IF bits = 16 AND chan = 1 THEN
  61.             REDIM leftMono AS INTEGER
  62.             GET #ch, , leftMono
  63.             lef = leftMono / RATE
  64.             righ = leftMono / RATE
  65.         END IF
  66.  
  67.         IF bits = 8 AND chan = 2 THEN
  68.             REDIM lleft8 AS _UNSIGNED _BYTE, rright8 AS _UNSIGNED _BYTE
  69.             GET #ch, , lleft8
  70.             GET #ch, , rright8
  71.             lef = lleft8 / 256
  72.             righ = rright8 / 256
  73.         END IF
  74.  
  75.         IF bits = 8 AND chan = 1 THEN
  76.             REDIM mono8 AS _UNSIGNED _BYTE
  77.             GET #ch, , mono8
  78.             lef = mono8 / 256
  79.             righ = lef
  80.         END IF
  81.  
  82.         IF RATE > 44100 THEN frekvence = RATE ELSE frekvence = 44100
  83.         FOR plll = 1 TO frekvence / RATE
  84.             _SNDRAW lef, righ
  85.         NEXT plll
  86.  
  87.         DO WHILE _SNDRAWLEN > 0: LOOP: REM comment this
  88.     LOOP
  89.     CLOSE ch
  90.  
  91.  
« Last Edit: October 10, 2018, 03:33:03 am by Petr »

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Compiler issue with sound commands
« Reply #48 on: October 10, 2018, 05:01:19 pm »
Yup, that did the trick, Petr. Even played the dog.wav correctly.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Compiler issue with sound commands
« Reply #49 on: October 10, 2018, 09:22:55 pm »
That MP3 specifically played with no issues on my machine until the end and I didn't encounter the issue with other files I had tested before. We use an external library for sound (OpenAL) and something must be interacting weirdly with your systems, but it's hard to pinpoint what exactly the issue may be.

Code: QB64: [Select]
  1. h& = _SNDOPEN("sulc.mp3")
  2. IF h& = 0 THEN PRINT "Loading failed.": END
  3.  
  4. PRINT "File loaded ok"
  5. PRINT "Sound length (seconds): "; _SNDLEN(h&)
  6. PRINT "Hit a key to start playing..."
  7. r = CSRLIN
  8. a$ = INPUT$(1)
  9.     LOCATE r, 1
  10.     PRINT USING "###.## / ###.##"; _SNDGETPOS(h&); _SNDLEN(h&)
  11.     _LIMIT 30

Now the dog.wav file not only didn't play on my machine but it also crashed when playing was attempted [EDIT: crash occurred when trying to load the file, I didn't even get to try playing it]. It may be encoded in too low a bitrate for the library to handle, but either way we'll have to wait for the C++ experts to be able to analyze what could be causing it, as well as the compilation error.

I was able to provide a solution to a recent issue of sound library not being able to be compiled on 64bit Linux systems (that's coming to a near-future dev build as soon as I can confirm it doesn't break 32bit versions), but that's a completely different beast.


If it breaks it would it be easier to just have a 32bit and and a 64bit version for download.. and the fix works great on my 64bit. :) cheers
MackyWhite

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Compiler issue with sound commands
« Reply #50 on: October 11, 2018, 04:26:49 pm »
Hi Petr,

First of all, I wonder how you figured out that synth.wav used 32-bit samples. Impressive forensic work.

Secondly, I'm surprised that anything actually uses or needs 32-bit samples. As far as I know, 24-bit is the most any music protocol uses? That's used for so-called high resolution audio, uncompressed. I mean, 16-bit, uncompressed, as used in CDs, already gives you a dynamic range of 96 dB. Human hearing can't even use 24-bit effectively, without serious damage to our ears. Even "only" 24-bit samples, uncompressed, would allow for more than 144 dB of dynamic range, and hearing loss begins to occur at about 110 dB.

Looking at your code, I wonder if it wouldn't be possible to write a generic player. For instance, it could accept anything from, say, 8 bits to 32 bits? Perhaps make all samples 32 bits, using the most significant bits only, and padding the least significant bits with zeroes? (I doubt anyone is thinking about 64-bit samples for music, but I could be wrong!)
« Last Edit: October 12, 2018, 04:01:29 pm by Bert22306 »