AQA GCSE Computer Science June 2022 Paper 1, Question 11: the sound file size subroutine

AQA 8525 June 2022 Paper 1, Question 11: fill six gaps in a subroutine that works out the size of a sound file in bytes, then explain local variables and the advantages of subroutines. Worked through, with the subroutine to run.

Past paper questionAQA 8525/1BJune 2022 Paper 110 marksComplete the algorithm

Question 11 of the AQA GCSE Computer Science June 2022 Paper 1 (8525/1B, the Python paper) joins two topics: the sound file size formula from Paper 2, and subroutines with parameters and return values. Part 1 is six gaps to fill (6 marks). Parts 2 and 3 are about local variables (1 mark) and why subroutines are used (3 marks).

We do not copy the exam paper here. Open it beside this page: AQA June 2022 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.

The question in short

The size of a sound file in bits is the sampling rate times the sample resolution times the number of seconds. Divide by 8 for bytes.

A subroutine called getSize should work that out, and the main program should output the size of a file sampled 100 times a second at 16 bits for 60 seconds. Six parts of the pseudo-code are blank. You fill them from a grid of sixteen items, and you will not need them all.

The skeleton looks like this, with each gap shown as a number:

  • SUBROUTINE getSize( 1 , 2 , seconds)
  • 3 ← sampRate * res * seconds
  • size ← 4
  • 5 size
  • ENDSUBROUTINE
  • OUTPUT 6 (100, 16, 60)

Work it through

Gaps 1 and 2 are sampRate and res. Look at the line below the heading. It uses sampRate, res and seconds. seconds is already a parameter, so the other two must be the missing ones. The order matters: the call passes 100, 16, 60, which is rate, resolution, seconds. rate is in the grid to tempt you, but the body of the subroutine never uses that name.

Gap 3 is size. The next line starts size ← and uses it, so this is where size first gets its value: the number of bits.

Gap 4 is size / 8. Bits to bytes is divide by 8. Not size * 8, which goes the wrong way. Not size MOD 8, which is the remainder.

Gap 5 is RETURN. The main program does the outputting, so the subroutine must hand the value back. If the subroutine used OUTPUT here, the OUTPUT on the last line would have nothing to show.

Gap 6 is getSize. It is the call to the subroutine.

The finished algorithm

Gap Answer
1 sampRate
2 res
3 size
4 size / 8
5 RETURN
6 getSize

One mark each. Gaps 1 and 2 must be that way round.

Part 2: what is a local variable?

A variable that can only be used inside the subroutine where it is made. Or: a variable that only exists while the subroutine is running. Either gets the mark.

Part 3: three advantages of subroutines

Any three, one mark each:

  • they can be written and tested on their own;
  • errors are easier to find, because each subroutine can be tested separately;
  • the code is easier to understand;
  • a team can work on different subroutines at the same time;
  • code can be reused, in this program or another one.

Where the marks are lost

  • res, sampRate. Parameters are matched by position. The call sends 100 first, and 100 is the sampling rate.
  • OUTPUT for gap 5. Check the last line: it outputs whatever getSize gives back. That needs RETURN.
  • "A local variable is inside a subroutine." Say what that means: it cannot be used outside it.
  • The same advantage three times. "Easier to read", "easier to understand" and "clearer" are one point, not three.

Run it

The subroutine in Python. Change the three numbers in the call and predict the size first.

It prints 12000.0: 100 x 16 x 60 is 96000 bits, and 96000 / 8 is 12000 bytes. The last line shows that size cannot be seen outside the subroutine.
The program
from bugbot import *
connect()

def get_size(samp_rate, res, seconds):
    size = samp_rate * res * seconds
    size = size / 8
    return size

print(get_size(100, 16, 60))

# CD quality for a three minute song, in megabytes
print(get_size(44100, 16, 180) * 2 / 1000000, "MB in stereo")

# size is local: it does not exist out here
try:
    print(size)
except NameError:
    print("size is local to get_size, so this line cannot see it")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What are the answers to AQA GCSE Computer Science 2022 Paper 1 Question 11.1?

The gaps are sampRate, res, size, size / 8, RETURN and getSize, in that order.

How do you calculate the size of a sound file?

Multiply the sampling rate by the sample resolution by the length in seconds to get the size in bits. Divide by 8 for bytes.

What is the difference between RETURN and OUTPUT in a subroutine?

OUTPUT shows a value to the user. RETURN passes a value back to the code that called the subroutine, so that it can be stored, used in a calculation or output there.

What is a local variable?

A local variable is declared inside a subroutine. It exists only while the subroutine runs and cannot be accessed from outside it.

More from this paper

Every AQA 8525 question we have worked · Guide: Sound sampling explained

Learn it step by step

  1. F4.2 Parameters and return values Functions and structured code
  2. F4.3 Local and global variables Functions and structured code
  3. F8.8 Sound Data representation
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.