memcpy der Soundfunktion streikt seit neuem IOS :(

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • memcpy der Soundfunktion streikt seit neuem IOS :(

    Hi!
    Nach kurzer Pause läuft meine rudimentäre Engine jetzt nicht mehr auf iPad. Seid neuem IOS und XCODE update.
    Es hängt an einer einzigen Stelle der Sound Funktion die aber vorher ohne Probleme funktioniert hat...

    Hier das Stückchen code, es ist die letzte Zeile darin die lautet:
    "memcpy( (char*)dst, &tmpBuff[0], ret);"
    Wenn ich sie auskommentiere hängt sich das Programm nicht mehr auf, aber der Sound geht nicht mehr ;(

    Der Fehlercode lautet: EXC_BAD_ACCESS ( code=1, adress... )
    Die Warnung der selben Zeile vorher: "Cast to char * from smaller integer type int"

    Wie kann es sein das das jetzt auch einmal streikt? Und wie bekomme ich den Dreher wieder raus?
    Oder kann es sein das ich meine OpenAL Framework updaten muss?

    Hoffe Ihr könnt mir helfen. 8|
    Danke!
    Ray

    Quellcode

    1. if ((fh = fopen([fsPath UTF8String], "r")) != NULL) {
    2. // open ogg file
    3. OggVorbis_File vf;
    4. int eof = 0;
    5. int current_section;
    6. if(ov_open(fh, &vf, NULL, 0) < 0) {
    7. NSLog(@"SoundOAL: Input does not appear to be an Ogg bitstream");
    8. [NSException raise:@"PASoundEngine:InvalidOggFormat" format:@"InvalidOggFormat"];
    9. }
    10. // get meta info (sample rate & mono/stereo format)
    11. vorbis_info *vi = ov_info(&vf,-1);
    12. freq = (ALsizei)vi->rate;
    13. format = (vi->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
    14. // decode data
    15. size = 0;
    16. char tmpBuff[kBuffSize];
    17. char *newData;
    18. while(!eof) {
    19. int ret = ov_read(&vf, &tmpBuff[0], kBuffSize, &current_section);
    20. if (ret == 0) {
    21. eof = 1;
    22. } else if (ret < 0) {
    23. /* error in the stream. Not a problem, just reporting it in
    24. case we (the app) cares. In this case, we don't. */
    25. NSLog(@"SoundOAL:Error reading buffer");
    26. [NSException raise:@"PASoundEngine:Error reading file" format:@"Error reading file"];
    27. } else {
    28. size += ret;
    29. // 1st malloc
    30. if( !data )
    31. newData = malloc(ret);
    32. else
    33. newData = realloc( data, size);
    34. if( ! newData ) {
    35. NSLog(@"SoundOAL: Not enough memory");
    36. [NSException raise:@"PASoundEngine:NotEnoughMemory" format:@"NotEnoughMemory"];
    37. }
    38. data = newData;
    39. int dst = (int)data + (size-ret);
    40. memcpy( (char*)dst, &tmpBuff[0], ret);
    41. }
    42. }
    Alles anzeigen
  • Ist vielleicht besser ich zeige die ganze Funktion, für den Fall der Fälle:

    Quellcode

    1. //Sounddaten mit Hilfe der Audio File API einlesen (AudioToolbox)
    2. - (void) loadSound:(NSString*) soundName andtype:(NSString*)soundType
    3. Hz:(NSUInteger) sampleRate {
    4. if ([soundType isEqualToString:@"wav"]) {
    5. //Sound-Datei oeffnen und fileID zuweisen
    6. OSStatus status;
    7. AudioFileID fileID;
    8. NSString *path = [[NSBundle mainBundle] pathForResource: soundName ofType: soundType];
    9. NSURL *afUrl = [NSURL fileURLWithPath: path];
    10. status = AudioFileOpenURL((CFURLRef) afUrl, kAudioFileReadPermission, 0, &fileID);
    11. [self logErrors: status];
    12. //Dateigroesse (fileSize) ermitteln
    13. UInt64 outDataSize = 0; //file size in bytes
    14. UInt32 thePropSize = sizeof(UInt64);
    15. status = AudioFileGetProperty(fileID, kAudioFilePropertyAudioDataByteCount, &thePropSize, &outDataSize);
    16. [self logErrors: status];
    17. UInt32 fileSize = (UInt32) outDataSize;
    18. //Sounddaten temporaer einlesen
    19. unsigned char *tempData = malloc(fileSize); //hier landen die einzelnen Samples
    20. status = AudioFileReadBytes(fileID, FALSE, 0, &fileSize, tempData);
    21. [self logErrors: status];
    22. status = AudioFileClose(fileID);
    23. //Einen neuen Audio-Buffer erzeugen
    24. NSUInteger bufferID;
    25. alGenBuffers(1, &bufferID);
    26. //Sounddaten als Raw Bytes in den Buffer schreiben (ohne Header-Information)
    27. alBufferData(bufferID, AL_FORMAT_STEREO16, tempData, fileSize, sampleRate);
    28. //Buffer in einem Dictionary ablegen
    29. [soundBufferIDDictionary setObject: [NSNumber numberWithUnsignedInt: bufferID] forKey: soundName];
    30. if(tempData) {
    31. free(tempData);
    32. tempData = NULL;
    33. }
    34. [self logErrors: status];
    35. }
    36. else if([soundType isEqualToString:@"ogg"])
    37. {
    38. ALenum error = AL_NO_ERROR;
    39. ALenum format = AL_FORMAT_STEREO16;
    40. ALvoid* data = NULL;
    41. ALsizei size = 0;
    42. ALsizei freq = 0;
    43. CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundName ofType:soundType]] retain];
    44. NSString *fsPath = [[NSBundle mainBundle] pathForResource: soundName ofType: soundType];
    45. // NSURL *afUrl = [NSURL fileURLWithPath: path];
    46. // NSString *fsPath = [(NSURL *)fileURL path];
    47. FILE *fh;
    48. if ((fh = fopen([fsPath UTF8String], "r")) != NULL) {
    49. // open ogg file
    50. OggVorbis_File vf;
    51. int eof = 0;
    52. int current_section;
    53. if(ov_open(fh, &vf, NULL, 0) < 0) {
    54. NSLog(@"SoundOAL: Input does not appear to be an Ogg bitstream");
    55. [NSException raise:@"PASoundEngine:InvalidOggFormat" format:@"InvalidOggFormat"];
    56. }
    57. // get meta info (sample rate & mono/stereo format)
    58. vorbis_info *vi = ov_info(&vf,-1);
    59. freq = (ALsizei)vi->rate;
    60. format = (vi->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
    61. // decode data
    62. size = 0;
    63. char tmpBuff[kBuffSize];
    64. char *newData;
    65. while(!eof) {
    66. int ret = ov_read(&vf, &tmpBuff[0], kBuffSize, &current_section);
    67. if (ret == 0) {
    68. eof = 1;
    69. } else if (ret < 0) {
    70. /* error in the stream. Not a problem, just reporting it in
    71. case we (the app) cares. In this case, we don't. */
    72. NSLog(@"SoundOAL:Error reading buffer");
    73. [NSException raise:@"PASoundEngine:Error reading file" format:@"Error reading file"];
    74. } else {
    75. size += ret;
    76. // 1st malloc
    77. if( !data )
    78. newData = malloc(ret);
    79. else
    80. newData = realloc( data, size);
    81. if( ! newData ) {
    82. NSLog(@"SoundOAL: Not enough memory");
    83. [NSException raise:@"PASoundEngine:NotEnoughMemory" format:@"NotEnoughMemory"];
    84. }
    85. NSLog(@"Value von ret %i", ret);
    86. data = newData;
    87. int dst = (int)data + (size-ret);
    88. memcpy( (char*)dst, &tmpBuff[0], ret);
    89. }
    90. }
    91. // close ogg file
    92. ov_clear(&vf);
    93. CFRelease(fileURL);
    94. if((error = alGetError()) != AL_NO_ERROR) {
    95. NSLog(@"SoundOAL: Error loading sound: %x", error);
    96. [NSException raise:@"PASoundEngine:ErrorLoadingSound" format:@"ErrorLoadingSound"];
    97. }
    98. NSUInteger buffer;
    99. // alGenBuffers(1, &bufferID);
    100. alGenBuffers(1, &buffer);
    101. alBufferData(buffer, format, data, size, freq);
    102. [soundBufferIDDictionary setObject: [NSNumber numberWithUnsignedInt: buffer] forKey: soundName];
    103. free(data);
    104. data = NULL;
    105. if((error = alGetError()) != AL_NO_ERROR) {
    106. NSLog(@"SoundOAL: Error attaching audio to buffer: %x", error);
    107. }
    108. }
    109. }
    110. }
    Alles anzeigen
  • Verwenden von LONG lässt das Programm sich nicht mehr aufhängen, aber die Soundfunktion funktioniert nicht mehr störungsfrei...

    Quellcode

    1. while(!eof) {
    2. long ret = ov_read(&vf, &tmpBuff[0], kBuffSize, &current_section);
    3. if (ret == 0) {
    4. eof = 1;
    5. } else if (ret < 0) {
    6. /* error in the stream. Not a problem, just reporting it in
    7. case we (the app) cares. In this case, we don't. */
    8. NSLog(@"SoundOAL:Error reading buffer");
    9. [NSException raise:@"PASoundEngine:Error reading file" format:@"Error reading file"];
    10. } else {
    11. size += ret;
    12. // 1st malloc
    13. if( !data )
    14. newData = malloc(ret);
    15. else
    16. newData = realloc( data, size);
    17. if( ! newData ) {
    18. NSLog(@"SoundOAL: Not enough memory");
    19. [NSException raise:@"PASoundEngine:NotEnoughMemory" format:@"NotEnoughMemory"];
    20. }
    21. data = newData;
    22. long dst = (long)data + (size-ret);
    23. memcpy( (char*)dst, &tmpBuff[0], ret);
    24. }
    25. }
    Alles anzeigen


    Jetzt bin ich mit meinem Latein am ende ;(
  • Ich habe mir das nur kurz durchgelesen, aber Zeilen 96 und folgende sind Quatsch.
    Ein "void *" hat keine Größe und das (long)data ist komplett falsch.

    Wenn die Sampledaten 8 byte groß sind muss die Pointer Kalkulation für dst sowas sein:

    Quellcode

    1. char *src;
    2. char *dst;
    3. size_t sz = size-ret;
    4. src = &tmpBuf[0];
    5. dst = &data[size - ret]
    6. memcpy(dst, src, ret);
  • Super, tausend dank, eine Zeile war unnötig, aber es läuft jetzt... macht aber noch seltsame Probleme indem er andere Sounds abspielt als angegeben, bzw diese noch falsch einlädt. Evtl. sind meine Sampledaten nicht 8 byte groß... Das Problem ist das ein bekannter die Funktion geschrieben hat der jetzt nicht mehr erreichbar ist, und ich habe keine Ahnung von sowas ^^ Schätze an der Bit Größe.

    Gerade aus dem Internet gezogen:
    "he line "bytes_read = ov_read(&vf, buffer, 4096,0,2,1,¤t_section)" specifies a buffer of 4096 bytes. That is what the line "This reads up to 4096 bytes into a buffer, with signed 16-bit little-endian samples." is refering to."

    Also 16 bit???

    Quellcode

    1. ​ //int dst = (int)data + (size-ret);
    2. //memcpy( (char*)dst, &tmpBuff[0], ret);
    3. char *src;
    4. char *dst;
    5. //size_t sz = size-ret; // unused
    6. src = &tmpBuff[0];
    7. dst = &data[size - ret];
    8. memcpy(dst, src, ret);
    Alles anzeigen