| 59 | |
| 60 | |
| 61 | EFI_STATUS |
| 62 | StartupSoundPlay(EFI_FILE *Dir, CONST CHAR16* SoundFile) |
| 63 | { |
| 64 | EFI_STATUS Status; |
| 65 | UINT8 *FileData = NULL; |
| 66 | UINTN FileDataLength = 0U; |
| 67 | WAVE_FILE_DATA WaveData; |
| 68 | UINT8 OutputVolume = DefaultAudioVolume; |
| 69 | UINT16 *TempData = NULL; |
| 70 | UINTN Len; |
| 71 | |
| 72 | if (OldChosenAudio >= AudioList.size()) { |
| 73 | OldChosenAudio = 0; //security correction |
| 74 | } |
| 75 | size_t OutputIndex = (OldChosenAudio & 0xFF); |
| 76 | |
| 77 | WaveData.Samples = NULL; |
| 78 | WaveData.SamplesLength = 0; |
| 79 | if (!AudioIo) { |
| 80 | Status = EFI_DEVICE_ERROR; |
| 81 | // DBG("not found AudioIo to play\n"); |
| 82 | goto DONE_ERROR; |
| 83 | } |
| 84 | |
| 85 | if (SoundFile) { |
| 86 | Status = egLoadFile(Dir, SoundFile, &FileData, &FileDataLength); |
| 87 | if (EFI_ERROR(Status)) { |
| 88 | // DBG("file sound read: %ls %s\n", SoundFile, efiStrError(Status)); |
| 89 | goto DONE_ERROR; |
| 90 | } |
| 91 | } else { |
| 92 | FileData = EmbeddedSound; |
| 93 | FileDataLength = EmbeddedSoundLength; |
| 94 | // DBG("got embedded sound\n"); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | Status = WaveGetFileData(FileData, (UINT32)FileDataLength, &WaveData); // |
| 99 | if (EFI_ERROR(Status)) { |
| 100 | MsgLog(" wrong sound file, wave status=%s\n", efiStrError(Status)); |
| 101 | //if error then data not allocated |
| 102 | goto DONE_ERROR; |
| 103 | } |
| 104 | Len = WaveData.SamplesLength; //byte length |
| 105 | MsgLog(" Channels: %hu Sample rate: %u Hz Bits: %hu\n", WaveData.Format->Channels, WaveData.Format->SamplesPerSec, WaveData.Format->BitsPerSample); |
| 106 | |
| 107 | EFI_AUDIO_IO_PROTOCOL_BITS bits; |
| 108 | switch (WaveData.Format->BitsPerSample) { |
| 109 | case 8: |
| 110 | bits = EfiAudioIoBits8; |
| 111 | break; |
| 112 | case 16: |
| 113 | bits = EfiAudioIoBits16; |
| 114 | break; |
| 115 | case 20: |
| 116 | bits = EfiAudioIoBits20; |
| 117 | break; |
| 118 | case 24: |
no test coverage detected