• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 18064138724

27 Sep 2025 04:20PM UTC coverage: 74.093% (+0.04%) from 74.05%
18064138724

push

github

Razakhel
[Utils/Logger] Added formatted logging overloads

- Formatted calls to logging functions and made use of std::format() in several other places

100 of 170 new or added lines in 36 files covered. (58.82%)

4 existing lines in 2 files now uncovered.

8334 of 11248 relevant lines covered (74.09%)

1757.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.31
/src/RaZ/Data/WavSave.cpp
1
#include "RaZ/Audio/Sound.hpp"
2
#include "RaZ/Data/WavFormat.hpp"
3
#include "RaZ/Utils/FilePath.hpp"
4
#include "RaZ/Utils/Logger.hpp"
5

6
#include "tracy/Tracy.hpp"
7

8
#include <array>
9
#include <fstream>
10

11
namespace Raz::WavFormat {
12

13
namespace {
14

15
constexpr std::array<char, 4> toLittleEndian32(uint32_t val) {
5✔
16
  return { static_cast<char>(val & 0xFFu), static_cast<char>((val >> 8u) & 0xFFu), static_cast<char>((val >> 16u) & 0xFFu), static_cast<char>(val >> 24u) };
5✔
17
}
18

19
constexpr std::array<char, 2> toLittleEndian16(uint16_t val) {
4✔
20
  return { static_cast<char>(val & 0xFFu), static_cast<char>(val >> 8u) };
4✔
21
}
22

23
} // namespace
24

25
void save(const FilePath& filePath, const AudioData& data) {
1✔
26
  ZoneScopedN("WavFormat::save");
27
  ZoneTextF("Path: %s", filePath.toUtf8().c_str());
28

29
  Logger::debug("[WavSave] Saving WAV file ('{}')...", filePath);
1✔
30

31
  std::ofstream file(filePath, std::ios_base::binary);
1✔
32

33
  if (!file)
1✔
NEW
34
    throw std::invalid_argument(std::format("[WavSave] Unable to create a WAV file as '{}'; path to file must exist", filePath));
×
35

36
  ////////////
37
  // Header //
38
  ////////////
39

40
  file << "RIFF";
1✔
41
  file.write(toLittleEndian32(static_cast<uint32_t>(data.buffer.size()) + 36).data(), 4); // File size - 8
2✔
42
  file << "WAVE";
1✔
43

44
  //////////////////
45
  // Audio format //
46
  //////////////////
47

48
  file << "fmt ";
1✔
49
  file.write(toLittleEndian32(16).data(), 4); // Format section size
2✔
50

51
  uint8_t bitCount {};
1✔
52

53
  switch (data.format) {
1✔
54
    case AudioFormat::MONO_U8:
×
55
    case AudioFormat::STEREO_U8:
56
      bitCount = 8;
×
57
      break;
×
58

59
    case AudioFormat::MONO_I16:
1✔
60
    case AudioFormat::STEREO_I16:
61
      bitCount = 16;
1✔
62
      break;
1✔
63

64
    case AudioFormat::MONO_F32:
×
65
    case AudioFormat::STEREO_F32:
66
      bitCount = 32;
×
67
      break;
×
68

69
    case AudioFormat::MONO_F64:
×
70
    case AudioFormat::STEREO_F64:
71
      bitCount = 64;
×
72
      break;
×
73

74
    default:
×
75
      throw std::invalid_argument("[WavSave] Unhandled audio format");
×
76
  }
77

78
  file.write(toLittleEndian16((bitCount >= 32 ? 3 : 1)).data(), 2); // Writing 1 if integer, 3 if floating-point
2✔
79

80
  uint16_t channelCount {};
1✔
81

82
  switch (data.format) {
1✔
83
    case AudioFormat::MONO_U8:
1✔
84
    case AudioFormat::MONO_I16:
85
    case AudioFormat::MONO_F32:
86
    case AudioFormat::MONO_F64:
87
      channelCount = 1;
1✔
88
      break;
1✔
89

90
    case AudioFormat::STEREO_U8:
×
91
    case AudioFormat::STEREO_I16:
92
    case AudioFormat::STEREO_F32:
93
    case AudioFormat::STEREO_F64:
94
      channelCount = 2;
×
95
      break;
×
96

97
    default:
×
98
      throw std::invalid_argument("[WavSave] Unhandled audio format");
×
99
  }
100

101
  file.write(toLittleEndian16(channelCount).data(), 2);
2✔
102
  file.write(toLittleEndian32(static_cast<uint32_t>(data.frequency)).data(), 4);
2✔
103

104
  const auto frameSize = static_cast<uint16_t>(bitCount / 8 * channelCount);
1✔
105

106
  file.write(toLittleEndian32(static_cast<uint32_t>(data.frequency) * frameSize).data(), 4); // Bytes per second
2✔
107
  file.write(toLittleEndian16(frameSize).data(), 2); // Bytes per block (bits per sample / 8 * channel count)
2✔
108
  file.write(toLittleEndian16(bitCount).data(), 2); // Bits per sample (bit depth)
2✔
109

110
  ////////////////
111
  // Data block //
112
  ////////////////
113

114
  file << "data";
1✔
115
  file.write(toLittleEndian32(static_cast<uint32_t>(data.buffer.size())).data(), 4);
2✔
116
  file.write(reinterpret_cast<const char*>(data.buffer.data()), static_cast<std::streamsize>(data.buffer.size()));
1✔
117

118
  Logger::debug("[WavSave] Saved WAV file");
1✔
119
}
1✔
120

121
} // namespace Raz::WavFormat
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc