Advertisement

error in sdl_mixer

Started by April 09, 2020 10:13 AM
7 comments, last by Prototype 4 years, 7 months ago

I write start of program to learn english (class and two files) and I want to play sound so I play it as wav files but I can't load it the compiler throw error “unsupported block alignment” I search on google I didn't found an answer can any person help….!

None

I load it with Mix_LoadWAV and I get error “unsupported block alignment”

None

Advertisement

this is my main class:

class Lrecord

{

public:

Lrecord();

~Lrecord();

Mix_Chunk* loadfile(char* chd);

void playfile(Mix_Chunk* mixc);

void init_lreco(int recordingDeviceId, int playbackDeviceId,char* cha1, char* cha2, char* cha3, char* chb1, char* chb2, char* chb3);

void init_recocall(int recordingDeviceId, int playbackDeviceId, char* chc, char* chd, int y);

//Focuses on window

void focus();

void handleEvent(SDL_Event& ev);

//Window dimensions

int getWidth();

int getHeight();

int handleEbutt(SDL_Event* e, int mposx, int mposy);

//Window focii

bool hasMouseFocus();

bool isMinimized();

bool isShown();

void free(SDL_Window* mWindow);

int handleEbuttMu(SDL_Event* e, int mux, int muy);

void setPosition(int x, int y);

Mix_Chunk* mix1;

private:

bool q1;

SDL_Window* lreco_window;

SDL_Renderer* lreco_render;

SDL_Texture* lreco_texture;

SDL_Texture* lreco_texture1;

SDL_Texture* lreco_texture2;

SDL_Texture* lreco_texture3;

SDL_Event e;

SDL_Rect lreco_rect;

SDL_Rect lreco_rect1;

//************************************************

//recoback

SDL_Window* recocall_window;

SDL_Renderer* recocall_render;

SDL_Texture* recocall_texture;

SDL_Rect rect1,rect2,rect3,rect4,rect5,rect6, recocall_rect;

SDL_Texture *texture1, *texture2, *texture3, *texture4, *texture5,

*texture6;

//************************************************

SDL_Window* mWindow;

//Window dimensions

int mWidth;

int mHeight;

bool quit;

//Window focus

bool mMouseFocus;

bool mKeyboardFocus;

bool mFullScreen;

bool mMinimized;

bool mShown;

int mWindowID;

//buttons veriables

bool mic;

bool stereo;

bool talk;

bool inside;

bool inside1;

SDL_Point mposition;

int x1, y1, a1;

Mix_Chunk* mix2;

Mix_Chunk* mix3;

};

Lrecord::Lrecord()

{

quit = false;

mMouseFocus = false;

mKeyboardFocus = false;

mFullScreen = false;

mShown = false;

mWindowID = -1;

mWindow = NULL;

mWidth = 0;

mHeight = 0;

Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);

x1 = y1 = a1 = 0;

}

and this is function for displaying a window

bool q1 = false;

Mix_Chunk* mix1 = loadfile(chb1);

mix2 = Mix_LoadWAV(chb2);

if (mix2 == NULL)

{

printf("Failed to load scratch sound effect1! SDL_mixer Error: %s\n", Mix_GetError());

}

mix3 = Mix_LoadWAV(chb3);

if (mix3 == NULL)

{

printf("Failed to load scratch sound effect2! SDL_mixer Error: %s\n", Mix_GetError());

}

mMouseFocus = true;

mWindow = SDL_CreateWindow("Main Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_SHOWN);

if (mWindow == NULL)

{

printf("%s", "main window can't be opened...!");

}

mMouseFocus = true;

lreco_render = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);

if (lreco_render == NULL)

{

printf("%s", "!renderer");

q1 = true;

}

//Grab window identifier

mWindowID = SDL_GetWindowID(mWindow);

//Flag as opened

mShown = true;

SDL_SetRenderDrawColor(lreco_render, 255, 255, 255, 255);

SDL_RenderClear(lreco_render);

SDL_RenderCopy(lreco_render, lreco_texture, NULL, &lreco_rect);

SDL_RenderPresent(lreco_render);

texture1 = IMG_LoadTexture(lreco_render, "images/mic-stereo.jpg");

rect1.x = 0;

rect1.y = 10;

rect1.w = 50;

rect1.h = 25;

SDL_RenderCopy(lreco_render, texture1, NULL, &rect1);

SDL_RenderPresent(lreco_render);

texture2 = IMG_LoadTexture(lreco_render, cha1);

rect2.x = 100;

rect2.y = 10;

rect2.w = 100;

rect2.h = 125;

SDL_RenderCopy(lreco_render, texture2, NULL, &rect2);

SDL_RenderPresent(lreco_render);

texture3 = IMG_LoadTexture(lreco_render, "images/mic-stereo.jpg");

rect3.x = 0;

rect3.y = 140;

rect3.w = 50;

rect3.h = 25;

SDL_RenderCopy(lreco_render, texture3, NULL, &rect3);

SDL_RenderPresent(lreco_render);

texture4 = IMG_LoadTexture(lreco_render, cha2);

rect4.x = 150;

rect4.y = 140;

rect4.w = 98;

rect4.h = 178;

SDL_RenderCopy(lreco_render, texture4, NULL, &rect4);

SDL_RenderPresent(lreco_render);

texture5 = IMG_LoadTexture(lreco_render, "images/mic-stereo.jpg");

rect5.x = 0;

rect5.y = 360;

rect5.w = 50;

rect5.h = 25;

SDL_RenderCopy(lreco_render, texture5, NULL, &rect5);

SDL_RenderPresent(lreco_render);

texture6 = IMG_LoadTexture(lreco_render, cha3);

rect6.x = 225;

rect6.y = 360;

rect6.w = 156;

rect6.h = 186;

SDL_RenderCopy(lreco_render, texture6, NULL, &rect6);

SDL_RenderPresent(lreco_render);

while (!q1)

{

if (SDL_PollEvent(&e))

{

if (e.type == SDL_WINDOWEVENT)

{

if (e.window.event == SDL_WINDOWEVENT_CLOSE)

{

if (mWindowID != 0 && mWindowID == e.window.windowID)

{

SDL_DestroyRenderer(lreco_render);

SDL_DestroyWindow(mWindow);

}

}

}

if (e.type == SDL_MOUSEBUTTONDOWN)

{

//If the left mouse button was pressed

if (e.button.button == SDL_BUTTON_LEFT)

{

//Get the mouse offsets

x1 = e.button.x;

y1 = e.button.y;

if ((y1 > 10) && (y1 < 35))

{

if ((x1 > 0) && (x1 < 25))

a1 = 1;

else if ((x1 > 25) && (x1 < 50))

a1 = 2;

}

else if ((y1 > 140) && (y1 < 165))

{

if ((x1 > 0) && (x1 < 25))

a1 = 3;

else if ((x1 > 25) && (x1 < 50))

a1 = 4;

}

else if ((y1 > 360) && (y1 < 385))

{

if ((x1 > 0) && (x1 < 25))

a1 = 5;

else if ((x1 > 25) && (x1 < 50))

a1 = 6;

}

}

}

}

switch (a1)

{

case 1:

playfile(mix1);

break;

case 2:

init_recocall(recordingDeviceId, playbackDeviceId, "a", cha1, 10);

break;

case 3:

Mix_PlayChannel(-1, mix2, 0);

break;

case 4:

init_recocall(recordingDeviceId, playbackDeviceId, "apple", cha2, 140);

break;

case 5:

Mix_PlayChannel(-1, mix3, 0);

break;

case 6:

init_recocall(recordingDeviceId, playbackDeviceId, "ant", cha3, 360);

break;

}

}

}

None

I hope you don't actually expect anyone to read through that code, because it is currently unreadable.

Four tips:

  1. Use the “insert code block” functionality to post code.
  2. Use descriptive variable names instead of garbage like ‘cha3’ and ‘q1’.
  3. Refactor your class into smaller classes that have a single responsibility. Put all of your audio code in one class that just handles audio and then post that, so that we don't have to sift through the rendering code to get to the code that actually matters.
  4. If you have a compile error, post the complete error message. If the compile error comes with a line number, identify the line with the error in your code.

the compiler throw error “unsupported block alignment”

None

the compiler return :("The program '[4244] Project16-record3.exe' has exited with code -1073741510 (0xc000013a).")

None

Advertisement

I use visual studio 2017

None

This is not a compiler error but a runtime error. The most likely cause is that you supplied an illegal WAV file. Have you tried some other files?

Note that WAV is an umbrella format that supports many variable options such as number of channels, sample rate, compression algorithm etc. Most commonly supported is mono-22Khz-(AD)PCM. You can use software like Audacity to check and convert formats.

This topic is closed to new replies.

Advertisement