from typing import BinaryIO
import io
import wave
import struct


def fixture_two_chunk_plain_wav() -> BinaryIO:
  """Creates a fixture WAVE file with two distinct sections.

  The audio is 100Hz mono. Each section 10 samples long. Samples in the first
  alternate between +/-(1 << 5) and in the second between +/-(1 << 10).

  Returns:
    File-like object with the bytes of the fixture WAVE file, positioned at the
      beginning.
  """
  sample_rate = 100
  chunk_duration_samples = 10

  plain_wav_io = io.BytesIO()
  with wave.open(plain_wav_io, 'wb') as writer:
    writer.setnchannels(1)
    writer.setsampwidth(2)
    writer.setframerate(sample_rate)
    signs = [pow(-1, i) for i in range(chunk_duration_samples)]
    for magnitude in [(1 << 5), (1 << 10)]:
      writer.writeframes(
          struct.pack('<%dh' % len(signs), *[magnitude * s for s in signs]))
  plain_wav_io.seek(0)
  return plain_wav_io