extras; samples: Fixed warnings
[sdk] / samples / audio / DirectBufferPlayer / wavPlayer.ec
index 929ad30..b9c87db 100644 (file)
@@ -1,71 +1,8 @@
-import "ecere"
-import "audio"
-
-#include <string.h>
-
-define AUDIO_BUFFER_SIZE = 21024;
-
-struct WAVEHDR
-{
-   byte   format[4]           __attribute__((packed));
-   uint32 f_len               __attribute__((packed));
-   byte   wave_fmt[8]         __attribute__((packed));
-   uint32 fmt_len             __attribute__((packed));
-   uint16 fmt_tag             __attribute__((packed));
-   uint16 channel             __attribute__((packed));
-   uint32 samples_per_sec     __attribute__((packed));
-   uint32 avg_bytes_per_sec   __attribute__((packed));
-   uint16 blk_align           __attribute__((packed));
-   uint16 bits_per_sample     __attribute__((packed));
-   byte   data[4]             __attribute__((packed));
-   uint32 data_len            __attribute__((packed));
-};
-
-public class Sound
-{
-public:
-   int frequency, bits, channels, length;
-   byte * data;
-
-   ~Sound()
-   {
-      delete data;
-   }
-
-   bool Load(char * fileName)
-   {
-      bool result = false;
-      WAVEHDR header;
-      File f = FileOpen(fileName, read);
-      if(f)
-      {
-         if(f.Read(header,sizeof(WAVEHDR),1) && !memcmp(header.format,"RIFF",4) && !memcmp(header.wave_fmt,"WAVEfmt ",8))
-         {
-            data = new byte[header.data_len];
-            if(data)
-            {
-               int c = f.Read(data, 1, header.data_len);
-               if(c)
-               {
-                  frequency = header.samples_per_sec;
-                  bits = header.bits_per_sample;
-                  channels = header.channel;
-                  length = Min(header.data_len, c);
-                  if(c < header.data_len)
-                     length -= 2048;
-                  result = true;
-               }
-            }
-         }
-         delete f;
-      }
-      return result;
-   }
-}
+import "EcereAudio"
 
 class Form1 : Window
 {
-   text = "Form1";
+   caption = "Form1";
    background = activeBorder;
    borderStyle = sizable;
    hasMaximize = true;
@@ -78,7 +15,7 @@ class Form1 : Window
 
    Button button1
    {
-      this, text = "Play", position = { 200, 168 };
+      this, caption = "Play", position = { 200, 168 };
 
       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
       {
@@ -90,7 +27,7 @@ class Form1 : Window
 
    bool OnPostCreate()
    {
-      if(sound.Load("test.wav"))
+      if(sound.Load("sweep.wav"))
       {
          AudioSpec wantedSpec
          {
@@ -113,7 +50,7 @@ class Form1 : Window
          return true;
       }
       else
-         MessageBox { contents = "test.wav not found" }.Modal();
+         MessageBox { contents = "sweep.wav not found" }.Modal();
       return false;
    }
 
@@ -125,7 +62,7 @@ class Form1 : Window
    void AudioCallback(byte *stream, int len)
    {
       static byte buffer[AUDIO_BUFFER_SIZE];
-      int s = Min(sound.length - pos, len);
+      int s = Min(sound.length * (sound.bits == 16 ? 2 : 1) - pos, len);
       memcpy(buffer, sound.data + pos, s);
       pos += s;
       if(s < len)